instanceof
运算符用来检测 constructor.prototype
是否存在于参数 object
的原型链
function Person(){
Person.prototype.dance=function(){};
}
function Ninja(){}
Ninja.prototype={dance:Person.prototype.dance};
const ninja=new Ninja();
console.log(ninja instanceof Ninja); //true
console.log(ninja instanceof Person); //false
console.log(ninja instanceof Object); //true
function Ninja(){}
const ninja=new Ninja();
console.log(ninja instanceof Ninja); //true
Ninja.prototype={};
console.log(ninja instanceof Ninja); //false