Prototype talk about what it is to understand the prototype chain, and when to use prototype?


  In js, prototype is a prototype function. Each function is an object, and has a property of the prototype, the property is an object, is a collection of attributes and methods.

  Chain prototype: Prototype __proto__ new instance of an object point to the instance of the object constructor function prototype prototype, then point to the original object prototype Object.prototype, point to null, form prototype chain.

  The advantage of using prototype is no additional memory, after all instantiated objects will inherit this property or method from the prototype. When a subclass need to have certain properties or methods of the parent class, property or method that can be overridden, but also can add your own properties and methods, this does not affect the parent class, this time using a prototype.

Guess you like

Origin www.cnblogs.com/wuqilang/p/11204645.html