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

343
Vistas
true call polyfil(without spread/rest operators); bonus: apply & bind polyfills

I've been practicing call, apply, bind polyfills and suddenly realized that it's not really a polyfill if I use spread/rest operators, can't figure out how to pass arguments in call without it, any ideas folks?

//my attempt to write call polyfil without spread operator
//but it doesn't work
Function.prototype.call = function () {
  const obj = arguments[0];
  obj.fn = this;
  const args = Array(arguments).slice(1).reverse();
  while (args.length) {
    obj.fn.arguments.push(args.pop());
  }

  //obj.fn.arguments = Array(arguments).slice(1);
  obj.fn();
};

// that one works, but it uses spread operator
Function.prototype.call = function (obj, ...args) {
  obj.fn = this;
  obj.fn(...args);
};

Function.prototype.apply = function (obj, args) {
  obj.fn = this;
  obj.fn(...args);
};

Function.prototype.myBind = function (obj, ...args) {
  const fn = this;

  return function (...newArgs) {
    const allArgs = [...args, ...newArgs];
    fn.call(obj, ...allArgs);
    //fn.apply(obj, allArgs);
  };
};

let obj = {
  name: "Jack",
};

let myFunc = function (id, city) {
  console.log(`${this.name}, ${id}, ${city}`); 
};

let newFunc = myFunc.myBind(obj, "a_random_id");
newFunc("New York"); // Jack, a_random_id, New York
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