1、手写call
Function.prototype.myCall = function (context, args) { context = context || window; context.fn = this; let result = context.fn(...args); delete context.fn; return result }
2、手写apply
Function.prototype.myApply = function (context, args) { context = context || window; context.fn = this; let result = context.fn(...args); delete context.fn; return result }
3、手写bind
Function.prototype.myBind = function (context, ...args) { context = context || window; context.fn = this; return function (..._args) { args = args.concat(_args); context.fn(...args); delete context.fn; } }