function A() {}
function B() {}
B.prototype = new A();
B.prototype.constructor = B;
B.prototype.bb = 1;
var b = new B();
//Object->__proto__->Function.prototype->__proto__->Object.prototype->__proto__->null
console.log('Object instanceof Object=' + (Object instanceof Object)); //true
console.log('Object instanceof Function=' + (Object instanceof Function)) //true
//Function->__proto__->Function.prototype->__proto__->Object.prototype->__proto__->null
console.log('Function instanceof Function=' + (Function instanceof Function)); //true
console.log('Function instanceof Object=' + (Function instanceof Object)); //true
//A->__proto->Function.prototype->__proto__->Object.prototype->__proto__->null
console.log('A instanceof Function=' + (A instanceof Function)); //true
console.log('A instanceof Object=' + (A instanceof Object)); //true
//B->__proto->Function.prototype->__proto__->Object.prototype->__proto__->null
console.log('B instanceof Function=' + (B instanceof Function)); //true
console.log('B instanceof Object=' + (B instanceof Object)); //false
console.log('B instanceof A=' + (B instanceof A)); //true
//b->__proto__->B.prototype->__proto__->A.prototype->__proto__->Object.prototype
console.log('b instanceof B=' + (b instanceof B)); //true
console.log('b instanceof A=' + (b instanceof A)); //true
console.log('b instanceof Function=' + (b instanceof Function)); //false
console.log('b instanceof Object=' + (b instanceof Object)); //true
console.log('b.prototype=' + b.prototype); //undefine
console.log(b.__proto__);
js中instanceof的分析
最新推荐文章于 2024-06-25 14:58:17 发布