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

103
Visualizações
Javascript bind polyfill function with return value

I have tried making bind polyfill using this link

It works fine when I use "console.log". But when I return something from the function, it returns undefined

Code:

let person1 = {
  name: "John",
  age: 25,
};

let showDetails = function () {
  let y = `${this.name} - ${this.age}`;
  // console.log(y) -> works fine
  return y;
};

Function.prototype.myBind = function (...args) {
  let that = this;
  params = args.slice(1);
  return function (...args1) {
    that.apply(args[0], [...params, ...args1]);
  };
};

let showDetailsBind = showDetails.myBind(person1);
console.log(showDetailsBind()); // returns -> undefined

Problem with this polyfill is, default bind function works completely fine with same procedure.

about 4 years ago · Santiago Trujillo
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