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

168
Vistas
Anonymous function: 'this' inside doesn't work

Lets say I have this code, with normal function:

let a = {
  parent: "roger",
  child: "bear",

  printName: function() {
    console.log(`${this.parent} ${this.child}`)
  }
}

b = {
  parent: "float",
  child: "bear",
}

a.printName.call(b)

The output is as expected:

float bear

However, the same code with anonymous function doesn't work:

let a = {
  parent: "roger",
  child: "bear",

  printName: () => {
    console.log(`${this.parent} ${this.child}`)
  }
}

b = {
  parent: "float",
  child: "bear",
}

a.printName.call(b)

This results in:

undefined undefined

Even passing 'this' to anonymous doesn't seem to work:

let a = {
    parent: "roger",
    child: "bear",

    printName: (this) => {
        console.log(`${this.parent} ${this.child}`)
    }
}

This results in a syntax error: Unexpected token this

Questions:

  • Please explain why is this happening?
  • How to get it to work?
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