第一種寫法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??
javascript對象聲明方式不同,打印結果也不一樣
翻過高山走不出你
2018-09-05 13:22:02