Facebook Pixel

Why should you not use an arrow function for the returned function in a bind polyfill?

Because arrow functions do not have their own this. The instanceof check (this instanceof boundFn) would not work with arrows. Use a regular function for the returned function.

Verify This Answer

Cross-check this information using these trusted sources:

More FAQs in bind Polyfill Common Mistakes

Because this inside the returned function is different from this inside myBind. Store it: const fn = this. Use fn in the returned function. Without this, the polyfill cannot call the original function.

The original function would not receive the arguments passed when the bound function is called. For greet.myBind(obj, 'Hello')('!'), the '!' would be lost. Always spread laterArgs: fn.call(context, ...presetArgs, ...laterArgs).

Because the real bind supports new. If a bound function is called with new, this should be the new instance, not the bound context. Without new support, new boundFn() would incorrectly use the bound context as this.

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