Prototype, the prototype chain, inheritance

Prototype, the prototype chain, inheritance

  • Each object in a property, that is, prototype (prototype), when we access an object's properties when its internal initialization

  • If this internal object this property does not exist, then he would go in looking for the prototype property, but this prototype will have its own prototype, so he has been looking so down, that is, the concept of what we usually prototype chain

  • 关系:instance.constructor.prototype = instance.proto

Features:

     JavaScript objects are passed by reference, each new object we created entity and not have a copy of their own prototypes. When we modify the prototype, the associated objects will inherit this change
when we need a property, Javascript engine will look at whether the current object has this attribute, if not

Will find out whether his Prototype object with this property, so recursive down, built-in objects have been retrieved Object
prototype

  • Each function has prototype property, except Function.prototype.bind (), which points to the prototype property.
  • Each object has __proto__ attribute points to create the object constructor prototype. In fact, this attribute points to the [[prototype]], but [[prototype]] internal property, we did not have access to, the use of proto access.
  • Objects can find attributes do not belong to the object by the __proto__, proto connect together to form the prototype chain objects

Guess you like

Origin blog.csdn.net/weixin_43931047/article/details/90676815