//手写call Function.prototype.myCall = function (context) { let ctx = context; ctx.fn = this; const args = Array.from(arguments).splice(1); let result = args.length > 0 ? ctx.fn(...args) : ctx.fn() Reflect.deleteProperty(ctx, 'fn'); return result; } //手写apply Function.prototype.myAplly = function (context) { let ctx = context; ctx.fn = this; let result = arguments ? ctx.fn(...arguments[1]) : ctx.fn() Reflect.deleteProperty(ctx, 'fn'); return result; } //手写bind Function.prototype.myBind = function (context) { let ctx = context; ctx.fn = this; const arg = Array.from(arguments).splice(1); return function () { const args = arg.concat(Array.from(arguments)); const result = args.length > 0 ? ctx.fn(...args) : ctx.fn(); Reflect.deleteProperty(ctx, 'fn'); return result; } } let obj = { a: 1, b: 2 } function fn(b) { console.log(this.a, b) } fn.myCall(obj, 12)