SOURCE

// myBind
Function.prototype.myBind = function (context) {  
  let realFunc = this
  const fBound = function () {
    return realFunc.apply(
    	this instanceof realFunc ?
      this : context,
      Array.from(arguments)
    )
  }
  
  if (this.prototype) {
  	fBound.prototype = Object.create(this.prototype)
  }
  
  return fBound
}

// call
Function.prototype.myCall = function () {
  const [context, ...args] = arguments
  const func = Symbol()
  context[func] = this
  return context[func](...args)
}

function NewObj () {
  const [func, ...args] = arguments
  if (typeof func !== 'function') {
    throw new Error('构造函数错误')
  }
  
  let obj = {}
  let res = func.apply(obj, args)
  return typeof res === 'object' ? res : obj
}

function a (){}
con
console 命令行工具 X clear

                    
>
console