call
Function.prototype.call = function call(context, ...params) {
context == null ? context = window : nullif (!/^(function|object)$/i.test(typeof context)) context = Object(context)let self = this,
key = Symbol('KEY'),
result
context[key] = self
result = context[key](...params)delete context[key]return result
}复制代码
apply
Function.prototype.apply = function apply(context, params) {
context == null ? context = window : nullif (!/^(function|object)$/i.test(typeof context)) context = Object(context)let self = this,
key = Symbol('KEY'),
result
context[key] = self
result = context[key](...params)delete context[key]return result
}复制代码
bind
Function.prototype.bind = function bind(context, ...params) {let self = this,
result
params = paramsreturn function proxy(...args) {
params = params.concat(args)
result = self.call(context, ...params)return result
}
}复制代码