So, what is polyfill?
Polyfill is a fallback for a method that is not supported by the browser by default. You can find browser support for any fu...
For further actions, you may consider blocking this person and/or reporting abuse
Great article, although, I don't think there is any need for this. It is 2021 and support for bind came between 2009 and 2011. Almost all operating systems for all types of devices comes with advanced built-in browsers that supports at least ES6 and almost all of them install and use modern browsers.
Totally agree, But first of all it helps us to understand how bind() works behind the scene. Apart from that i was asked to implement polyfill of bind() in few interviews as well.
this example is to understand how the black box works
Nice article Uddesh.
Implementing
bind
withapply
is kind of cheating 😉I haven't used bind very often since arrow functions
Arrow function are really helpful for adopting ‘this’ from their parent and in most of the use cases we don’t need ‘bind()’, But what if you want ‘this’ to refer to a particular object then you need to use ‘bind()’. I hope you got my point.
To be honest, I only use bind for it's less well known second Param. I avoid using this and prefer pure functions, I have very few reasons to make this do anything, bimut that's just me ☺️
This is a pretty cool post.
I would like to make a small alteration in your code.
We can eliminate the need for storing 'this' in the parent scope and using it at the time by invocation by making use of arrow function.
Hope this helps!!
This myBind does not give the expected output. It gives undefined for both consoles.
Why because there is no return in your myBind return function. To fix this add return before func.apply line.
Good one. 🌟🌟
Thanks. 🙂