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

231
Vistas
How exactly does javascript set context for objects created from constructor function using the new keyword

Consider the following constructor function having a method logging the context

function Foo() {
  this.logContext1 = () => console.log('logContext1', this);
}

let foo = new Foo();

foo.logContext2 = () => console.log('logContext2', this);

foo.logContext1();
foo.logContext2();

logContext1 has context (this) set to the Foo object created by new,

whereas logContext2 has context (this) set to the window object

Considering both are arrow functions, why do we see this difference?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

this is defined where the arrow functions are declared:

  • () => console.log('logContext1', this) is declared in the constructor, this is the object being created in that context
  • () => console.log('logContext2', this) is declared on top-level, this is window in that context (or undefined in strict mode)
about 4 years ago · Juan Pablo Isaza Denunciar
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