Last active
November 5, 2021 03:31
-
-
Save abhinavnigam2207/af3d494524568a231caf6794d61f7d23 to your computer and use it in GitHub Desktop.
Call Polyfill
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function.prototype.myCall = function(context, ...args) { | |
context.fnName = this; | |
context.fnName(...args); | |
} | |
/* Usage*/ | |
function showProfileMessage(message) { | |
console.log(message, this.name); | |
} | |
const obj = { | |
name: "Abhinav Nigam" | |
}; | |
showProfileMessage.myCall(obj, "welcome "); |
Maybe it will be more correct:
Function.prototype.myCall = function(context, ...args) {
context.fnName = this;
context.fnName(...args);
}
Thanks @Volodymyrprodyus for pointing out. Updated the gist
fnName should be deleted after its execution as call doesn't edit the context we pass.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it doesn't show
welcome
=)