Javascript's new is just a simulation of the class. This is why JavaScript classes are not classes in the industry-because they are simulated.
In fact, the New Keyword of JavaScript only does five things.
1. Create an object
2. Search for all the methods and attributes on the prototype of the class and copy them to the created object. (Note: if the prototype has the function, array, or object attributes, copy only the pointer)
3. Point this in the constructor classa to the created object.
4. The _ PROTO _ of the created object points to the prototype of the class.
5. Execute the constructor class
See the example:
// Define the class name as classa <br/> function classa () {<br/> This. B = 1; <br/>}< br/> classa. prototype. B = 44; <br/> classa. prototype. show = function () {<br/> alert (this. b); <br/>}; <br/> // instantiate with new <br/> var B = new classa (); <br/> B. show (); <br/> // instantiate with a function <br/> function newclass (CLS, argS) {<br/> var OBJ = {}; <br/> for (var p in Cls. prototype) <br/> OBJ [p] = Cls. prototype [p]; <br/> obj. _ PROTO _ = Cls. prototype; <br/> Cls. apply (OBJ, argS | []); <br/> return OBJ; <br/>}; <br/> var K = newclass (classa ); <br/> K. show (); <br/>
Reprinted from http://constructor.iteye.com/blog/990434