Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

413
Views
¿Qué hace 'nuevo' para modificar el objeto 'esto' en una función?

¿Qué hace la new palabra clave que permite el siguiente enlace en this objeto:

 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();

Mientras que sin la new palabra clave, this.first generaría un error ya que no está definido. Conceptualmente hablando, ¿qué es lo new que hace aquí en cómo modifica la función?

Sin new :

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


Y sin usar new looks, la siguiente es una forma cruda de simularlo:

 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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!