SOURCE

function Dog(name, age) {
    this.name = name;
    this.age = age;
}

Dog.prototype.bark = function () {
    console.log(`${this.name}: wang wang wang!`);
}

Dog.prototype.details = function () {
    console.log(`It's a ${this.age} year-old dog named ${this.name}`);
}
let dog1 = new Dog('yooyoo', 5);
dog1.bark();
dog1.details();
console.log(dog1 instanceof Dog);

// 创建对象
// 新对象的原型指向目标构造函数的原型
// 执行构造函数取得构造函数的属性
// 返回对象
function myNew(){
    let obj = {}
    const Constructor = [].shift.call(arguments)
    obj.__proto__ = Constructor.prototype
    Constructor.apply(obj,arguments)
    return obj;
}


let dog2 = myNew(Dog, 'foofoo', 2);
dog2.bark();
dog2.details();
console.log(dog2 instanceof Dog);
console 命令行工具 X clear

                    
>
console