function Box() { this.name = 'zhang'; }
function Desk() { this.age = 100; }
function Table() { this.lever = 1000 }
Desk.prototype = new Box();//通过原型链继承
var desk = new Desk();
var table = new Table();
alert(desk instanceof Box);
输出true,因为desk是Desk的实例,所有的Desk都拥有prototype这个属性,而Desk的prototype是Box的实例,所以向上查找能找到Box
function Box() { this.name = 'zhang'; }
function Desk() { this.age = 100; }
function Table() { this.lever = 1000 }
Desk.prototype = new Box();//通过原型链继承
var desk = new Desk();
var table = new Table();
alert(Desk instanceof Box);
输出false,因为Desk的原型才是Box的实例,Desk不是
Desk {age: 100}age: 100[[Prototype]]: Box 输出desk
ƒ Desk() { this.age = 100; } 输出Desk
Desk是一个函数,所以输出的就是这个函数,而desk是Desk的实例,输出的是里面有属性的一个对象,这个对象具有prototype属性,属性值是Box的实例,体现出来的也是Box