Javascript - Check if a function exists
12 Jul 2010 à 14:27 par itimeteo
In order to check if a function exists before trying to call it (and get a fatal error), we can use typeof.
Here is the javascript code :
Fil des commentaires
| 1. |
if(typeof window.functionToCall == 'function') {
|
| 2. |
// The function exists, so we can now call it :
|
| 3. |
functionToCall('test', 'hipi!');
|
| 4. |
}
|
Fil des commentaires
Pas de commentaire pour le moment.