Function.prototype.myApply = function (thisObj, ...args) { if (typeof this !== 'function') { throw TypeError('this is not a function'); } const O = thisObj || window; O.fun = this; const result = O.fun(...args); delete O.fun; return result; }