Facebook Pixel
bind Polyfill: Step-by-Step Explanation

What is this inside the myBind function in a bind polyfill?

The answer

this is the function on which myBind is called. For greet.myBind(obj), this is greet. Store it: const fn = this, and use it in the returned function.

More FAQs in bind Polyfill: Step-by-Step Explanation

presetArgs are passed to myBind: greet.myBind(obj, 'Hello'). laterArgs are passed when the bound function is called: bound('!'). Both are spread into fn.call: fn.call(context, ...presetArgs, ...laterArgs).

To support the new operator. When a bound function is called with new, this should be the new instance, not the bound context. this instanceof boundFn is true only when called with new.

new boundFn() would set this to the bound context instead of a new instance. This is incorrect behavior. The real bind supports new, so the polyfill should too.

Still have questions?

Browse all our FAQs or reach out to our support team

Want to upskill yourself?

Your learning library

Small steps. Big possibilities.

Find your next course. Build something great.

Our courses are taking a Coffee break, but your curiosity shouldn't. Stay engaged with namastedev linkedin, youtube, discord and other resources while you wait.

0

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.