prototype、constructor、

mac2022-06-30  24

 1  function Person() {  2         }  3   4         Person.prototype.name = "Nicholas";  5         Person.prototype.age = 29;  6         Person.prototype.job = "Software Engineer";  7         Person.prototype.sayName =  function () {  8             console.log( this.name);  9         }; 10  11          var person1 =  new Person(); 12         person1.sayName(); 13  14          var person2 =  new Person(); 15         person2.sayName(); 16  17         console.log(person1.sayName == person2.sayName); // 函数相等 18         console.log(Person.constructor); 19         console.log(Person.prototype.constructor); 20         console.log(person1.__proto__); 21         console.log(person2.__proto__);

转载于:https://www.cnblogs.com/qzsonline/archive/2012/03/26/2417981.html

最新回复(0)