views:

32

answers:

1

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  A: 

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(); 
  }
} 
bendewey
so, is ok to use something like this? without breaking any browsers? i don not want browser to prompt for errors when rendering page
cometta
It all depends on when the doSomethingNow is called in relation to when callSomethingInFuture is declared, so I won't say never. To be safe use one of my safety checks.
bendewey
will it be any rendering problem on old browsers? or mobile phone browser? any error will be throws?
cometta
There shouldn't be. but to be safe use one the the safety checks.
bendewey