faqts : Computers : Programming : Languages : JavaScript : Language Core : Functions

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

439 of 471 people (93%) answered Yes
Recently 10 of 10 people (100%) answered Yes

Entry

How can I check if a function exists?

May 11th, 2002 11:28
Acebone,


Got it!
<html>
<head>
	<title>Untitled</title>
<SCRIPT LANGUAGE="JavaScript" type="text/javascript">
<!--
function findMe()
{//
   alert('you found me!')
}
/**
 * can't use
 *  if ( findMe ) {}
 * functions are methods of some object
 * in this case the window object
 * 
 * only looking for findMe would require an object called findMe
 */
if ( window.findMe )
{
   findMe()
}
else
{
    alert( 'not found' )
}
//-->
</SCRIPT>
</head>
</html>