var person = {
name: "Neo",
friends: ["Toby", "Tina"]
}
var toby = Object.create(person, { friends: {
value: ["Neo", "Tina", "Jim"]
} });
console.log(toby.friends);
var tina = Object.create(person, { friends: {
value: ["Neo", "Lucy", "Caitlin"]
} });
console.log(tina.friends);
輸出結果:
輸出結果
在沒有必要興師動眾地創(chuàng)建構造函數(shù),而只想讓一個對象與另一個對象保持類似的情況下,原型式繼承是完全可以勝任的。