Look at the code first
var Func=function(){ }; var func=new Func ();
new has gone through 4 stages in total
var obj=new Object();
obj.__proto__= Func.prototype;
var result =Func.call(obj);
4. Determine the return value type of Func:
If it is a value type, return obj. If it is a reference type, an object of this reference type is returned.
if (typeof(result) == "object"){ func=result;}else{ func=obj;;}
Use hidden new to create objects
How to use new StdClass() to create in php Empty object?
The above is the detailed content of The 4 stages of object creation using the new keyword. For more information, please follow other related articles on the PHP Chinese website!