JS

JS中Constructor好用法:

即在只知道一个对象实例的情况下(不知道对象名),重新初始化一个新实例;

 1 function Person( firstname, lastname, age ) {
 2   this.firstname = firstname;
 3   this.lastname = lastname;
 4   this.age = age;
 5 }
 6 
 7 var dave = new Person("Dave", "Smith", 28);
 8 
 9 document.write( dave.constructor + "<br />");
10 // function Person(firstname, lastname, age) { this.firstname = firstname; this.lastname = lastname; this.age = age; }
11 
12 // we can create a new object from another object's constructor:
13 var mike = new dave.constructor("Mike", "Fox", 22);
14 
15 // Is mike an instance of the Person object?
16 document.write( mike.constructor == Person );    // true
原文地址:https://www.cnblogs.com/tx8899/p/4721237.html