function _new() {
  let obj = {}                              // Create a new object
  let _constructor = [].shift.call(arguments)        // Get the constructor
  obj.__proto__ = _constructor.prototype             // Link to the prototype
  let result = _constructor.apply(obj, arguments)    // bind this and execute the constructor
  return result instanceof Object ? result : obj    // Make sure the return value is an object
}
Copy the code