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

130
Vistas
Passing "this" with bind returns undefined. Returning "this" returns windows object
  class ObjectMapping {
    constructor(value) {
        this.value = value;
    }
      map(func) {
        let b = func.bind(this)()
        console.log(b);
    }
  }
  
  const m = new ObjectMapping({ abc: 'abc',
      def: 'def' });
  const func = (value) => {
      return this[value]
  };
  
  m.map(func);

The func function is part of my assignment so it can't be changed but I can mess around with it to see what it returns.

const func = (value) => {
    return this //returns windows object
};

When I set it to just this, I get back the windows object regardless of what I pass in.

const func = (value) => {
    return value //returns undefined
};

When I bind it, it returns undefined.

map(func) {
   let key = Object.keys(this.value)[0] //key = abc
   let b = func(key)
   console.log(b);
}
const func = (value) => {
    return this.value
};

I tried passing in the the key but I still get undefined. How do I pass in an object and not get back the windows object?

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