Facebook Pixel

What is the time complexity of bind in JavaScript?

bind itself is O(1) - it just creates a closure. The returned function has the same time complexity as the original function. bind does not add any algorithmic overhead.

Verify This Answer

Cross-check this information using these trusted sources:

More FAQs in bind Polyfill Interview Questions

Function.prototype.myBind = function(context, ...presetArgs) { const fn = this; return function(...laterArgs) { return fn.call(context, ...presetArgs, ...laterArgs); }; }.

Check this instanceof boundFn. If true, return new fn(...presetArgs, ...laterArgs). Otherwise, return fn.call(context, ...presetArgs, ...laterArgs).

No. Arrow functions have lexical this. call (used inside the polyfill) cannot change an arrow's this. This is the same behavior as the native bind.

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.