1 function Person(name, age, job) {
 2             this.name = name;
 3             this.age = age;
 4             this.job = job;
 5             this.sayName = function () {
 6                 console.log(this.name);
 7             };
 8         }
 9 
10         var person1 = new Person("Nicholas", 29, "Software Engineer");
11         var person2 = new Person("Greg", 27, "Doctor");
12 
13         person1.sayName();
14         person2.sayName();
15         
16         console.log(person1.constructor);
17         console.log(person2.constructor);
18         console.log(person1 instanceof Object);
19         console.log(person1 instanceof Person);
20         console.log(person2 instanceof Object);
21         console.log(person2 instanceof Person);

相关文章:

  • 2022-12-23
  • 2021-11-06
  • 2021-06-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-24
  • 2021-09-01
  • 2022-12-23
  • 2021-08-14
  • 2022-12-23
相关资源
相似解决方案