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__);

prototype、constructor、__proto__

相关文章:

  • 2021-08-29
  • 2021-05-30
  • 2021-06-08
  • 2021-07-18
  • 2022-12-23
猜你喜欢
  • 2021-07-13
  • 2021-11-05
  • 2021-06-21
  • 2022-12-23
  • 2022-12-23
  • 2021-04-27
  • 2022-12-23
相关资源
相似解决方案