function Car() {}
let car = new Car()
class Car {}
let car = new Car
function Car(name) {this.name = name}
function Car(name) {this.name = name; return {age: name}}
function myNew(fn) {
return function() {
let obj = {}
obj.__proto__ = fn.prototype
let res = fn.call(obj, ...arguments)
return typeof res === 'object' ? res : obj
}
//
return function() {
let obj = Object.create(fn.prototype)
let res = fn.apply(obj, arguments)
return typeof res === 'object' ? res : obj
}
}
function myNew2() {
let obj = {};
let Constructor = Array.prototype.shift.call(arguments);
obj.__proto__ = Constructor.prototype;
let res = Constructor.call(obj, ...arguments)
return typeof res === 'object' ? res : obj
}
myNew(Car)('red')
myNew2(Car, 'red')