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

421
Vistas
What does 'new' do to modify the `this` object in a function?

What does the new keyword do that allows the following binding on the this object:

function Person(first, last) {
    this.first = first;
    this.last = last;
}
Person.prototype.greet = function() {
    console.log(`Hello, ${this.first} ${this.last}.`);
};
let p = new Person('Tom', 'Jones');
p.greet();

Whereas without the new keyword, this.first would raise an error since it is undefined. Conceptually speaking, what is new doing here in how it modifies the function?

Without new:

function Person(first, last) {
    this.first = first;
    this.last = last;
}
Person('Tom', 'Jones');
// TypeError: Cannot set property 'first' of undefined


And without using new seems the following is a crude way to simulate it:

function Person(first, last) {
    this.first = first;
    this.last = last;
    return this;
}
Person.prototype.greet = function() {
    console.log(`Hello, ${this.first} ${this.last}.`);
};

Person.prototype.greet.call(Person.call({}, 'Tom', 'Jones'));

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