Use typeof to determine whether the function exists in the context

  • 2020-03-30 03:43:28
  • OfStack

When the window loads, use typeof to determine whether the function exists in the context


<script type="text/javascript"> 
window.onload = function(){ 
try{ 
if(test && typeof(test) == "function"){ 
test(); 
} 
}catch(e){ 
alert(" Method does not exist "); 
} 
} 
function test(){ 
alert(" I am a test() methods "); 
} 
</script>

Related articles: