Facebook Pixel

What happens if you do not support new in a bind polyfill?

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.

Verify This Answer

Cross-check this information using these trusted sources:

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

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.

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.

Still have questions?

Browse all our FAQs or reach out to our support team

Want to upskill yourself?

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
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.