What did New do?

    1. A new object is created
    1. Attach the __proto__ property of the new object to the constructor’s prototype,
    1. Call this once and call this to the newly created object, passing in arguments to determine the return value
    1. If the constructor returns no value, or is not a reference type, return a new object; Otherwise, the return value of the constructor.
    function myNew(func) {
    	letres = {}; // create a new objectif(func.prototype ! == null) { res.__proto__ = func.prototype; // 2. Point the constructor's prototype object to the new object's prototype property}letret = func.apply(res, Array.prototype.slice.call(arguments, 1)); // 3. Point this of the constructor to the newly created object and call the constructorif ((typeof ret === "Object" || typeof ret === "Array") && ret ! == null) {// If the constructor has a return value and is a reference type, return it, otherwise return a new objectreturn ret
        }
    	return res
}Copy the code