new的原理
    let obj = {};
    obj. proto = Fn.prototype;
    Fn.call(obj);

    新建一个空对象;
    将对象的原型proto指向构造函数的prototype
    将函数的this指针指向新对象 并调用函数;

    手写一个new
    关键点是使用proto或Object.create()继承函数原型和方法,并将this指向新建的对象

    1. function myNew () {
    2. let obj = {};
    3. // arguments的第一个值为构造函数
    4. const constructor = Array.prototype.shift.call(arguments);
    5. const args = arguments;
    6. obj.__proto__ = constructor.prototype;
    7. constructor.call(obj, ...args);
    8. return obj;
    9. }
    10. // Fn是构造函数,args为参数
    11. let newObj = myNew(Fn, args);

    https://www.jianshu.com/p/44052c58040d