Frontend101 logoFrontend101
← Problems
#16EasyJavaScript functions

16. Function.prototype.call

JavaScriptClosures & Scope

Implement Function.prototype.myCall(thisArg, ...args) without calling native call() or apply().

Example 1:
function greet(prefix) { return prefix + " " + this.name; }
greet.myCall({ name: "Satish" }, "Hello"); // "Hello Satish"
solution.js
Invokes function with given thisArg and args
(() => {
          function greet(p) { return p + " " + this.name; }
          expect(greet.myCall({ name: "Satish" }, "Hi")).toBe("Hi Satish");
        })()