猿问

请问chrome中console.log打印的对象名是指向哪里?

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

打印结果:

如图所示:b 和 C.prototype 都是 构造函数B 的实例化对象,为何打印这两个对象的时候, b 显示的结果第一个字母是B,而C.prototype显示的第一个字母是A,而两个通过 instanceof 和 constructor 的结果都一致,请大神们帮忙解惑,万分感谢


弑天下
浏览 489回答 1
1回答

MM们

具体请查看 javascript 对原型链的解释。继承与原型链instanceof
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答