SOURCE

function myNew(){
    const args = [...arguments]
    const parent = args.shift()
    
	const o = new Object()
	o.__proto__ = parent.prototype
    
	// const o = Object.create(parent.prototype)
	const ret = parent.apply(o, args)
    // console.log(ret)
	return typeof ret === 'object' ? ret : o
}

function foo(arg1){
	this.name = arg1
}
function bar(arg1){
	return { ab: arg1 }
}
const foo1 = myNew(foo, 2) // new foo(2)
const bar1 = myNew(bar, 3) //

console.log('foo1:', foo1)

console.log('bar1:', bar1)
console 命令行工具 X clear

                    
>
console