Function.prototype.myCall = function(context) { if (typeofthis !== 'function') thrownewError('Error') context = context || window context.fn = this let args = [...arguments].slice(1) let result = context.fn(...args) delete context.fn return result }
Function.prototype.MyApply = function (context) { if (typeofthis !== 'function') thrownewTypeError('Error') context = context || window context.fn = this let result if (arguments[1]) { result = context.fn(...arguments[1]) } else { result = context.fn() } delete context.fn return result }