首页  >  文章  >  web前端  >  使用typeof判断function是否存在于上下文_javascript技巧

使用typeof判断function是否存在于上下文_javascript技巧

WBOY
WBOY原创
2016-05-16 16:39:311422浏览

在窗口加载时,使用typeof判断function是否存在于上下文

<script type="text/javascript"> 
window.onload = function(){ 
try{ 
if(test && typeof(test) == "function"){ 
test(); 
} 
}catch(e){ 
alert("方法不存在"); 
} 
} 
function test(){ 
alert("我是test()方法"); 
} 
</script>
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn