[Notes] [Javascript] A shallow understanding of prototypes and prototype chains

foreword

  • Prototype and prototype chain are necessary knowledge for learning front-end
  • Some of the notes in the notes have been sorted out after personal understanding, and there may be deviations. Readers are also kindly requested to help point out, thank you.

disclaimer

  • For convenience, some of the pictures used in this article come from the Internet. If there is any infringement, please contact the blogger to delete it. Thanks to other bloggers for their pictures.
  • This note is used to record my summary of this knowledge. To facilitate future work and study.
  • If there is any infringement, please inform and delete it immediately.

prototype

[What is it?

  • The prototype property of the function (also known as the prototype object)

[What can be done?

  • Put some properties and methods and share them with instance objects.
  • Can do inheritance.

prototype chain

[What is it?

  • _proto_The chain structure formed by one object and one layer of attributes becomes the prototype chain

    • The line connected at the bottom of the figure below is the prototype chain.

      [External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-KVMscu3E-1684766861575)(https://cdn.acwing.com/media/article/image/2021/11 /05/11468_a30078ec3d-QQ%E5%9B%BE%E7%89%8720211105121221.png#pic_center)]

      The property of the object _proto_, this property also points to its prototype object, the prototype object is also an object, and also has _proto_properties, pointing to the prototype object of the prototype object, and so on until it reaches the top level and cannot find it, then return null.

Good article recommendation

[1]. Fairy Tail, "Easy Understanding of JS Prototype Prototype Chain", Rare Earth Nuggets, 2019-11-07

Guess you like

Origin blog.csdn.net/weixin_45944495/article/details/130817040