let say i have function like below
function doSomethingNow(){
callSomethingInFutureNotExistNow();
}
at the moment doSometingNow() is created callSomethingInFutureNotExistNow() not exist yet. It will be created in the future, on firefox, this doesn't show any error on firebug. Will these kind of function compatible on all browsers without throwing errors ?
1 Answer 1
Since javascript isn't compiled you shouldn't ever receive any errors with the code you posted assuming you don't call doSomethingNow() before callSomethingInFutureNotExistNow is declared.
To be safe though, you may want to do some null checking
function doSomethingNow(){
if (callSomethingInFutureNotExistNow) {
callSomethingInFutureNotExistNow();
}
}
Or if you want to be even more strict you can do type checking like this
function doSomethingNow(){
if (typeof(callSomethingInFutureNotExistNow) === 'function') {
callSomethingInFutureNotExistNow();
}
}
callSomethingInFutureNotExistNowbefore you calldoSomethingNow.