Open weijiyang opened 5 years ago
Function.prototype.apply = function (context) {
let ctx = context || window
ctx.func = this
return argument.length > 1 ? ctx.func(arguments[1]) : ctx.func()
}
Function.prototype.bind = function (context) {
let ctx = context || window
ctx.func = this
let args = Array.from(arguments.slice(1))
return function () {
let param = args.concat(...arguments)
let res = param.length ? ctx.func(param) : ctx.func()
delete ctx.func
return res
}
}
注意: