Prototype mode each function (not exactly a class, an object.) has a prototype property, which is a pointer to an object. Using the prototype object'sBenefitsIs that you can have all object instances share the properties and methods that it contains. 1. Prototype objects (1) When a new function is created, a prototype property is created for the function, which points to the prototype object of the function. (2) By default, all prototype objects automatically get a constructor (constructor) property that contains a pointer to thefunction where the prototype property is locatedThe pointer. (3) The inner part of the instance contains a pointer, called [[Prototype]]. But the pointer to the scriptcompletely invisible (some browsers support a __proto__ to access)。 2. Code read attribute Ordersearch the object instance itself first, without continuing to search for the prototype object pointed to by the pointer. Example: function person () {} person.prototype.name= "Javascript"; var p1 = new Person (); var p2 = new Person (); P1.name= "Lufeng"; alert (p1.name);//"Lufeng" alert (p2.name);//"Javascript" uses the delete operator to completely remove instance properties. isPrototypeOf (): Determines if there is a prototype relationship between Objects hasOwnProperty (): detects whether an attribute exists in an instance or exists in a prototype. Object.keys (), Object.getownpropertynames (): Receives an object as a parameter and returns an array of strings containing all the enumerable properties. See a veryThe egg hurts .Class Inheritance (some HTML5 game frame): Inherit:function (ChildClass, ParentClass) {var Constructor = new function () ; Constructor.prototype = Parentclass.prototype; Childclass.prototype = new Constructor (); ChildClass.prototype.constructor = ChildClass; Childclass.superclass = Parentclass.prototype; if (ChildClass.prototype.constructor = = Object.prototype.constructor) {childClass.prototype.constructor = P Arentclass; }} feel the code seems a bit messy, I drew a picture:
Javascript: Prototype pattern class inheritance