`
ssg108
  • 浏览: 50367 次
  • 性别: Icon_minigender_2
  • 来自: 郑州
社区版块
存档分类
最新评论

JS中的instanceof和typeof

阅读更多

JS中的instanceof和typeof :

http://wasabi.iteye.com/blog/179335

 

 疑问:

 

function f(){ return f; }

alert(new f());  // function f(){ return f; }

alert(new f() instanceof f);       //弹出结果是false;

 

function f(){ }

alert(new f());  //object

 alert(new f() instanceof f);     //弹出结果是true;

 

 

答案: ‘new’ returns an instance of the class, unless the function that defines the class returns something else that is an object. So in this case, new f() just returns the function f itself and not an instance of it.

 

 

 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics