Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

150
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda