Description of the new keyword: from the MDN

The new keyword does the following:

1. Create an empty simple Javascript object (i.e. {});

2. Link this object (that is, set its constructor) to another object;

3. Use the newly created object in Step 1 as the context for this.

4. If the function returns no object, return this;

The Call implementation does not pass objects:

Function myNew(fn) {let o = object.create (fn. Prototype); Fn let k = fn.call(o); O if (typeof k === 'object') {return k; } else { return o; }}Copy the code

Apply passes the parameter:

function myNew(fn, ... Let o = object.create (fn. Prototype) // Change fn's this to point to o, Let k = fn.apply(o, args); O if (typeof k === 'object') {return k; } else { return o; }}Copy the code