Home  >  Article  >  Web Front-end  >  Use typeof to determine whether a function exists in the context_javascript tips

Use typeof to determine whether a function exists in the context_javascript tips

WBOY
WBOYOriginal
2016-05-16 16:39:311470browse

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("方法不存在"); 
} 
} 
function test(){ 
alert("我是test()方法"); 
} 
</script>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn