Function.prototype.myCall = function(context){
if(typeof this !== 'function'){
throw new TypeError('Error')
}
context = context || window
context.fn = this
const args = [...arguments].slice(1)
const res = context.fn(args.toString())
delete context.fn
return res
}
Function.prototype.myBind = function(context){
if(typeof this !== 'function'){
throw new TypeError('Error')
}
const _this = this
const args = [...arguments].slice(1)
return function F(){
if(this instanceof F){
return new _this(...args,...arguments)
}
return _this.apply(context,args.concat(...arguments) )
}
}
console