Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

if there is function available run it, if not do not 2

Status
Not open for further replies.

HotFrost

Technical User
Aug 19, 2003
5
US
Hi everyone,

i wonder what construction should i use to do the following..

i have a function. Inside of it, i would like to see if other function is available on the page. If yes, then run it, if not, do not call it. The page is ASP.NET.

there is javascript library that i modifying to call my function. But i don't need to call that function (or place it on the page everytime i am using a control that uses javascript library).

thanks for any suggestiongs !
 
Suppose the function under examination is named y, then it is this.
[tt]
if (y && typeof y=="function") {
//the function exists and ready to be called
} else {
//the contrary
}
[/tt]
If it is too stripped down to make you feel comfortable, dress it up like this to look more formal.
[tt]
if (window["y"] && typeof window["y"]=="function") {
//the function exists and ready to be called
} else {
//the contrary
}
[/tt]
 
Here is another solution:
Code:
...
try {
  functionNameToCall();
} catch(e) {
// do nothing
}
...
Nothing wrong with doing a try-catch in this scenario, IMHO.

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top