js代碼:
function A(x){ this.x = x ; }function B(y) { this.y = y; }B.prototype = new A(1);function C(z) { this.z = z; } var b = new B(2); C.prototype = new B(2);console.log(b); console.log(C.prototype);console.log(b instanceof A); console.log(C.prototype instanceof A); console.log(b.constructor); console.log(C.prototype.constructor);
打印結(jié)果:
如圖所示:b 和 C.prototype 都是 構(gòu)造函數(shù)B 的實(shí)例化對(duì)象,為何打印這兩個(gè)對(duì)象的時(shí)候, b 顯示的結(jié)果第一個(gè)字母是B,而C.prototype顯示的第一個(gè)字母是A,而兩個(gè)通過(guò) instanceof 和 constructor 的結(jié)果都一致,請(qǐng)大神們幫忙解惑,萬(wàn)分感謝