[ Web Proxy ]
URL:
Viewing: https://uk.javascript.info/function-prototype [Back]  [Original]

F.prototype
:
DanskEnglishEspaolFranaisIndonesiaItalianoTrkeOzbek
29 2025 .

F.prototype

, -, new F().

F.prototype , new [[Prototype]] .

, :

JavaScript . .

, , . 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 , rabbit [[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" ,

JavaScript "constructor".

, constructor "prototype" , . "constructor" .

, prototype , prototype "constructor".

:

function Rabbit() {}
Rabbit.prototype = {
  jumps: true
};

let rabbit = new Rabbit();
alert(rabbit.constructor === Rabbit); // false

, "constructor", prototype , "prototype":

function Rabbit() {}

//       Rabbit.prototype
//     
Rabbit.prototype.jumps = true
//    Rabbit.prototype.constructor 

, constructor :

Rabbit.prototype = {
  jumps: true,
  constructor: Rabbit
};

//  , constructor  ,      

[[Prototype]] , -. , , .

, :

  • F.prototype ( [[Prototype]]) [[Prototype]] , , new F().
  • F.prototype , null: .
  • "prototype" : new.

prototype :

let user = {
  name: "John",
  prototype: "Bla-bla" //   
};

, F.prototype = { constructor: F }, "constructor".

: 5

, , - new Rabbit prototype.

, :

function Rabbit() {}
Rabbit.prototype = {
  eats: true
};

let rabbit = new Rabbit();

alert( rabbit.eats ); // true
  1. (). alert?

    function Rabbit() {}
    Rabbit.prototype = {
      eats: true
    };
    
    let rabbit = new Rabbit();
    
    Rabbit.prototype = {};
    
    alert( rabbit.eats ); // ?
  2. ( )?

    function Rabbit() {}
    Rabbit.prototype = {
      eats: true
    };
    
    let rabbit = new Rabbit();
    
    Rabbit.prototype.eats = false;
    
    alert( rabbit.eats ); // ?
  3. ( )?

    function Rabbit() {}
    Rabbit.prototype = {
      eats: true
    };
    
    let rabbit = new Rabbit();
    
    delete rabbit.eats;
    
    alert( rabbit.eats ); // ?
  4. :

    function Rabbit() {}
    Rabbit.prototype = {
      eats: true
    };
    
    let rabbit = new Rabbit();
    
    delete Rabbit.prototype.eats;
    
    alert( rabbit.eats ); // ?

:

  1. true.

    Rabbit.prototype [[Prototype]] , . .

  2. false.

    . Rabbit.prototype . Rabbit.prototype, [[Prototype]] rabbit.

    , , .

  3. true.

    delete . delete rabbit.eats eats rabbit, . .

  4. undefined.

    eats , .

: 5

, obj, - , .

?

let obj2 = new obj.constructor();

- obj, , , , , .

, , "constructor" .

, "prototype", :

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

let user = new User('');
let user2 = new user.constructor('');

alert( user2.name ); //  (!)

, User.prototype.constructor == User.

, , User.prototype constructor User, .

:

function User(name) {
  this.name = name;
}
User.prototype = {}; // (*)

let user = new User('');
let user2 = new user.constructor('');

alert( user2.name ); // undefined

user2.name undefined?

new user.constructor('') :

  1. , constructor user. .
  2. . user User.prototype, constructor ( !).
  3. , , User.prototype , Object.prototype.
  4. , Object.prototype, Object.prototype.constructor == Object .

, , , let user2 = new Object('').

, , . new User, new Object. constructor.

( , , new Object(...) . , new Object ; , new Object ).

,

Web Proxy Viewer  |  New URL  |  Original Page