If you are here, I guess you would either be looking for new opportunities or honing your skills. I would like to help for either reasons with this article. Let's directly jump in to the topic without wasting our read time π€
Polyfill for Call
Explanation:
What exactly is this π§ -> arguments[0].fn = this;
In this above statement this refers to calling function i.e; displayUser
- We are creating a property(fn) on object and assigning displayUser function to it
- Above would create an additional property
fnon the passed object(user) - Now,
fnwould have access tothison user object asfnis user objects property now - So, pass only parameters now to function
fnnow, as it takes care ofthis - Both
runCallandrunCall2are valid polyfills forcallwhererunCall2has defined parameters andrunCalldepends onargumentsobject - Look at the code below and compare with lines written inside function
runCall
Polyfill for Apply
Apply polyfill is similar to call except that apply takes arguments as Array along with object(context)
Polyfill for Bind
Here comes the solution for our wait, atleast I feel though π
There are two functions created for bind polyfill in the above code. One is using [].slice.call(arguments) and the other one is using rest/spread syntax ...arguments
Thank you for taking time to read my article. I know there would always be something to improve. Please feel free to share your thoughts π
Top comments (2)
arguments[0].fn(...[].slice.call(arguments,1)); You implementing call polyfill using call, how is that even polyfill?
@ivasilichi Thanks for pointing this out. I was more concentrating on "bind" polyfill and overlooked "call". I was also not active on this forum so far. It is corrected/updated now. Thanks again