cometta
cometta

Reputation: 35719

call future javascript function compatibility on all browsers?

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 ?

Upvotes: 0

Views: 225

Answers (1)

bendewey
bendewey

Reputation: 40265

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(); 
  }
} 

Upvotes: 1

Related Questions