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

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


<script type="text/javascript">
window.onload = function(){
try{
if(test && typeof(test) == "function"){
文章正文

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

<script type="text/javascript"> 
window.onload = function(){ 
try{ 
if(test && typeof(test) == "function"){ 
test(); 
} 
}catch(e){ 
alert("方法不存在"); 
} 
} 
function test(){ 
alert("我是test()方法"); 
} 
</script>

代码注释

作者:喵哥笔记

IDC笔记

学的不仅是技术,更是梦想!