对象的constructor属性

对象的constructor属性, 最初是用来标识对象类型的。

比如 ,我们定义一个 Person类,然后实例化两个对象。
function Person(name, age, job){
this.name = name;
this.age = age;
this.job = job;
this.sayName = function(){
alert(this.name);
};
}
var person1 = new Person(“Jam”, 25, “Software Engineer”);
var person2 = new Person(“Tom”, 27, “Doctor”);
 
这两个对象 都有 一个constructor 属性,该属性指向 Person
lert(person1.constructor == Person); //true
alert(person2.constructor == Person); //true
 
不过,提到对象类型检测,我们一般不这样做, 
因为 instanceof 操作符 更可靠一些
往往是这样用 alert(person1 instanceof Person); //true
原文地址:https://www.cnblogs.com/iwangzheng/p/3577946.html