第一种写法
var stone={
weight:100
}
// function stone() {
// this.weight=100;
// }
function Bench() {
this.legth=100;
this.width=50;
this.weight=60;
}
Bench.prototype=stone;
var b=new Bench();
console.log(b);
console.log(Object.getPrototypeOf(b));
结果:
第二种写法:
function stone() { this.weight=100; }function Bench() { this.legth=100; this.width=50; this.weight=60; } Bench.prototype=new stone;var b=new Bench();console.log(b);console.log(Object.getPrototypeOf(b));
为什么会这样,第二种前面会带stone??
倚天杖
相关分类