Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

149
Views
Is a robust `Function.prototype.bind` polyfill possible?

In conjunction with Function.prototype.apply and Function.prototype.call, Function.prototype.bind is used by Node.js to preserve "primordial" prototype methods in a form usable by its internal library and unaffected by any mutations to builtins by user code. This is the relevant section from primordials.js:

// `uncurryThis` is equivalent to `func => Function.prototype.call.bind(func)`.
// It is using `bind.bind(call)` to avoid using `Function.prototype.bind`
// and `Function.prototype.call` after it may have been mutated by users.
const { apply, bind, call } = Function.prototype;
const uncurryThis = bind.bind(call);
primordials.uncurryThis = uncurryThis;

// `applyBind` is equivalent to `func => Function.prototype.apply.bind(func)`.
// It is using `bind.bind(apply)` to avoid using `Function.prototype.bind`
// and `Function.prototype.apply` after it may have been mutated by users.
const applyBind = bind.bind(apply);
primordials.applyBind = applyBind;

All that is needed to save Array for internal library use is to assign it to a variable scoped to the internal libraries. Saving Array.prototype.push for reuse is trickier because it normally has to be a property of an object to work. uncurryThis(Array.prototype.push) produces a function whose first parameter is the this value that gets used by Array.prototype.push, which is now usable even if user code deletes the method from the prototype of Array.

Unlike apply and call, bind is unavailable in older JavaScript engines, so it cannot be used to save preserve builtin methods. P"Bound" functions returned by polyfills for Function.prototype.bind that I have encountered thus far are written a way that is susceptible to breaking if, for instance, apply and call were deleted from Function.prototype.

Is there some way to polyfill Function.prototype.bind in such a way that functions returned by it cannot be broken by monkey patching?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!