__proto__、prototype、constructor 之间的关系

引用 李松峰 老师的PPT

 

 1 var Person = function(living, age, gender) {

 2   this.living = living;

 3   this.age = age;

 4   this.gender = gender;  

 5 };

 6 

 7 Person.prototype.getGender = function(){

 8   return this.gender;

 9 };

10 

11 var child = new Person(true, 25, 'male');

12 

13 console.log (child.getGender()); // male

14 console.log (child.__proto__ === Person.prototype);//true

15 console.log (child.constructor === Person);//true

 

 

你可能感兴趣的:(Constructor)