/* Use the following Code , You can simulate the new implementation in ff and chrome * // work as a constructor to create an objectfunction constructorfn (name) {This. name = Name;} // Add a method to its prototype. note: just a function has a prototype propertyconstructorfn. prototype. calla = function () {alert ('I am calla') ;}; // Add a property to itss prototypeconstructorfn. prototype. propertyb = "I am property B"; function objectfactory () {// obtain the first parameter, essentially a function As a constructor, similar to arguments. Shift (), arguments is an array-like object. Shift removes the first element in the array and returns this element. // Question: Why can't I directly call arguments. Shift? VaR constructor = array. prototype. shift. call (arguments);/* browsers that support the _ PROTO _ attribute, such as FF or chrome, can change the corresponding prototype chain before calling. Arguments. _ PROTO _ = array. prototype; var constructor = arguments. shift (); * // the first step of New is to generate an object var OBJ ={}; // the second step of New is to change the original prototype chain of the object, so that it is equal to the prototype of the corresponding constructor. Therefore, all attributes and methods of the constructor prototype can use OBJ in the newly generated object. _ PROTO _ = (typeof constructor. prototype = 'number ')? The third step of object. prototype: constructor. Prototype; // new is to call the corresponding constructor and pass the object as the this pointer of the constructor. VaR ret = constructor. apply (OBJ, arguments); // at this time, arguments has removed the first element, that is, the following parameter section, in essence, is the constructor return (typeof ret = 'object') called ')? RET: OBJ;}; // var A = objectfactory (constructorfn, 'tenfyguo') constructed by simulating new; alert (. name);. calla (); alert (. propertyb); // var B = new constructorfn ('hello'); alert (B. name); B. calla (); alert (B. propertyb );