坏小仔

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
View Code
1 function Person(){
2 
3 }
4 
5 Person.prototype = {
6   name: "june";      
7   age: 24  
8 };

上面代码中:

Person.prototype的constructor属性不再指向Person;

每创建一个函数,默认创建它的prototype对象,这个对象自动获得constructor属性;上述写法本质是重写了默认的prototype对象,因此constructor属性指向Object构造函数,不再指向Person函数。

View Code
var person  = new Person();
alert(person instanceof Object) ; //true
alert(person instanceof Person) ; //true
alert(person.constructor == Object) ; //true
alert(person.constructor == Person) ; //false

 

 

posted on 2013-03-24 09:19  坏小仔  阅读(168)  评论(0编辑  收藏  举报