SOURCE

function Person(name, age) {
    this.name = name
    this.age = age
    this.say = function() {
        return `he is ${this.name} ${this.age}`
    }
}

function newFunc (Constructor, ...args) {
    // 创建新对象
    const obj = {}
    // 新对象的__proto__等于构造函数的prototype
    obj.__proto__ = Constructor.prototype
    // 新对象作为构造函数的this
    let result = Constructor.apply(obj, args)
    return result || obj
}

const person = new newFunc(Person, 'labike', 19)
console.log(person.say())
console 命令行工具 X clear

                    
>
console