javascript - object constructor pointing to Object function after redefining prototype of self defined function -


Whenever I've redefined the prototype of the function and made it a new object, its constructor root object function itself Function explain me with this scenario:

  var person = function (firstName, lastName) {this.firstName = firstName; This.lastName = lastName; } Person.prototype.getFullName = function () {return this.firstName + "" + this.lastName; } Var Student = New Person ("Ankur", "Agarwal"); Student.constructor // The person who is correct   

After that I redefine the person prototype and

  Person.prototype = {} Var manager = New Person ('John', 'Smith'); What is the number of the manager.constructor // object?   

In addition, if the object is pointing to luck, then how does it come to use the names of persons like the first name and last name?

Enter image details here

<

This.lastName = lastName; }

There is a default prototype property, which is an object manufacturer property reference person manufacturer. This is such property that (by default) examples are succession through the [[prototype]] series.

When you create an example, the first name and last name properties are defined on the example, such as:

 < Code> var person = {firstName: ..., lastName: ...};   

Then those properties are unaffected by the prototype of the constructor.

When a new object constructor's prototype is assigned:

  Person.prototype = {};   

It receives a constructor property from Object.prototype (which is its constructor). So before reaching the example constructor , for example, its [[prototype]] (Person.prototype), then its [[prototype]] Looks at (Object.prototype) and objects for a reference. You can do this:

  person.prototype.constructor = person;   

You can find more information on MDN.

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -