new F().
F.prototype new [[Prototype]] .
. .
. "prototype" . .
F.prototype "prototype" F . 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 [[Prototype]] .
F.prototype (F.prototype = < >) new F [[Prototype]] .
F.prototype
"prototype" .
"prototype" constructor .
:
function Rabbit() {}
/* prototype
Rabbit.prototype = { constructor: Rabbit };
*/
:
function Rabbit() {}
// :
// Rabbit.prototype = { constructor: Rabbit }
alert( Rabbit.prototype.constructor == Rabbit ); // true
constructor [[Prototype]] :
function Rabbit() {}
// :
// Rabbit.prototype = { constructor: Rabbit }
let rabbit = new Rabbit(); // {constructor: Rabbit}
alert(rabbit.constructor == Rabbit); // true ( )
constructor .
:
function Rabbit(name) {
this.name = name;
alert(name);
}
let rabbit = new Rabbit(" ");
let rabbit2 = new rabbit.constructor(" ");
( ) .
"constructor"
*** "constructor" .**
"prototype" . .
"constructor" .
:
function Rabbit() {}
Rabbit.prototype = {
jumps: true
};
let rabbit = new Rabbit();
alert(rabbit.constructor === Rabbit); // false
"constructor" "prototype" :
function Rabbit() {}
// Rabbit.prototype
//
Rabbit.prototype.jumps = true
// Rabbit.prototype.constructor
constructor :
Rabbit.prototype = {
jumps: true,
constructor: Rabbit
};
//
[[Prototype]] . .
:
-
F.prototype([[Prototype]])[[Prototype]]new F(). -
F.prototypenull: . -
"prototype"new.
prototype :
let user = {
name: "John",
prototype: "Bla-bla" //
};
F.prototype = { constructor: F } "constructor" .
<code><pre>. (plnkr jsbin codepen)