new F() .
' . new [[Prototype]] .
.
. "prototype" . .
(F) F.prototype "prototype" F . F.prototype "prototype" ' .
:
let animal = {
eats: true
};
function Rabbit(name) {
this.name = name;
}
Rabbit.prototype = animal;
let rabbit = new Rabbit(" "); // rabbit.__proto__ == animal
alert( rabbit.eats ); // true
Rabbit.prototype = animal "new Rabbit [[Prototype]] animal ." .
.
"prototype", [[Prototype]] . rabbit animal .
F.prototype new F .F.prototype new F . new F [[Prototype]] .
F.prototype (F.prototype = <another object>) new F another object [[Prototype]] . , [[Prototype]] .
prototype constructor
"prototype" .
( ) "prototype" constructor , constructor .
.
function Rabbit() {}
/* prototype
Rabbit.prototype = { constructor: Rabbit };
*/
.
function Rabbit() {}
// prototype .
// Rabbit.prototype = { constructor: Rabbit }
alert( Rabbit.prototype.constructor == Rabbit ); // true
new Rabbit constructor , [[Prototype]] .
function Rabbit() {}
// prototype:
// Rabbit.prototype = { constructor: Rabbit }
let rabbit = new Rabbit(); // {constructor: Rabbit}
alert(rabbit.constructor == Rabbit); // true ([[Prototype]] )
constructor constructor .
.
function Rabbit(name) {
this.name = name;
alert(name);
}
let rabbit = new Rabbit(" ");
let rabbit2 = new rabbit.constructor(" ");
( ) .
"constructor"
"constructor" .
"prototype" . "constructor" .
"prototype" . new "constructor" .
:
function Rabbit() {}
Rabbit.prototype = {
jumps: true
};
let rabbit = new Rabbit();
alert(rabbit.constructor === Rabbit); // false
constructor "prototype" "prototype" "prototype" , .
function Rabbit() {}
// Rabbit.prototype
// .
Rabbit.prototype.jumps = true
// Rabbit.prototype.constructor .
"prototype" constructor constructor .
Rabbit.prototype = {
jumps: true,
constructor: Rabbit
};
// constructor constructor .
[[Prototype]] . .
.
- (
F.prototype)[[Prototype]].F.prototypenew F()[[Prototype]]. F.prototypenull . .-
new.
"prototype" .
let user = {
name: "John",
prototype: "Bla-bla" // .
};
F.prototype = { constructor : F } "constructor" .
<code>,<pre>. 10 plnkr, JSBin, codepen .