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

138
Vistas
Equating Variable with Object Method

I was working through a JS newsletter which had a little quiz for what would be the output of the following program:

window.name = "Mike Tyson";

const me = {
    name: "Tyler",
    sayName(): {
        console.log(this.name);
    },
};

const sayName = me.sayName;
sayName();

Why does this print "Mike Tyson" instead of "Tyler"? When I set a variable (sayName) equal to an object method, I had thought the variable would be referencing the name variable inside the object it is defined in since it would close over its lexical scope even when called outside it (can confirm me.sayName() does print "Tyler").

My understanding of variables referencing objects & functions must be incorrect

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