Function.prototype.apply = function(context, rest) { const ctx = context || window; ctx.fn = this; let result; if (rest) { result = eval("ctx.fn(...rest)"); } else { result = eval("ctx.fn()"); } delete ctx.fn; return result; }; const me = { name: 'Jack' } function say() { console.log(`My name is ${this.name || 'default'}`); } say.apply(me)