Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

153
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda