0

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 ?

asked Feb 27, 2010 at 16:54
2
  • will it be any rendering problem on old browsers? or mobile phone browser? any error will be throws? Commented Feb 27, 2010 at 17:10
  • No. If there will be, it will be because you "forgot" to declare callSomethingInFutureNotExistNow before you call doSomethingNow. Commented Feb 27, 2010 at 17:27

1 Answer 1

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(); 
 }
} 
answered Feb 27, 2010 at 16:56
Sign up to request clarification or add additional context in comments.

4 Comments

so, is ok to use something like this? without breaking any browsers? i don not want browser to prompt for errors when rendering page
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.
will it be any rendering problem on old browsers? or mobile phone browser? any error will be throws?
There shouldn't be. but to be safe use one the the safety checks.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.