js中instanceof的分析

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__);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值