instanceof
instanceof运算符用于测试构造函数的prototype属性是否出现在对象的原型链中的任何位置
function Car(make, model, year) {
this.make = make;
this.model = model;
this.year = year;
}
var auto = new Car('Honda', 'Accord', 1998);
console.log(auto instanceof Car);
// expected output: true
console.log(auto instanceof Object);
// expected output: true
object- 要检测的对象.
constructor- 某个构造函数

浙公网安备 33010602011771号