/** new - 1. New obj = {} 2. Bind this 4. Return, if the constructor returns an object, it returns that object. Otherwise, the new object */ is returned
function myNew(constructor, ...arguments) {
let obj = {}
Object.setPrototypeOf(obj,constructor.prototype)
console.log(arguments);
// This bind: apply bind obj new object
let other = constructor.apply(obj, arguments)
console.log(other);
return typeof other === 'object' ? other : obj;
}
function Product(name,price) {
this.name = name
this.price = price
Yu returns a non-object distinction
return {
'hero': 'hh'}}let p = myNew(Product, 'jm'.20)
console.log(p );
Copy the code