I’m calling a function like this :
$.myFunction
Depending on version a user may have of the .js file where the function resides the function may not be called successfully since it does not exist. If this function does not run I just want to ignore any errors that are thrown and continue execution. One workaround is to wrap the function in a try/catch :
try {
$.myFunction
}
catch(e){
}
But it seems bad practice to me to use a try/catch in this way. Is there jQuery/javascript method to check if a function exists before running it ?
I’m supposing you’re calling the function as
You may test
But it’s a little strange to have to do that on a library. Aren’t you including it yourself ? To try to do with any version of a lib just as if it was complete seems dangerous.