F.prototype

物件被建構函式創造時,像是 new F(),[[Prototype]] 被設置為 F.prototype。

// 建構函式有 prototype 屬性,可以繼承原型物件
let animal = {
  eats: true
};

function Rabbit(name) {
  this.name = name;
}

Rabbit.prototype = animal; // 當 new Rabbit 被創造 [[Prototype]] 的值為 animal

let rabbit = new Rabbit("White Rabbit"); //  rabbit.__proto__ == animal

alert( rabbit.eats ); // true

Default F.prototype, constructor property

Last updated

Was this helpful?