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

302
Views
¿Qué sucede con los objetos existentes cuando declaras la herencia del prototipo?

 //debugger; function User(email,name) { this.email = email; this.name = name; this.online = false; } User.prototype.login = function() { this.online = true; console.log('this.name is now online'); } function Admin(...args) { User.apply(this, args); this.title = 'admin'; } const admin1 = new Admin('admin@admin.com', 'josh'); Admin.prototype.deleteUser = function() { console.log('deleted user'); } Admin.prototype = Object.create(User.prototype); const admin2 = new Admin('admin2@admin.com', 'barry'); console.log(admin1); //admin1 will have the deleteUser() method in its prototype, and DIDN'T update after Admin inherited the User prototype console.log(admin2); //admin1 will have the login() method and NOT deleteUser()

¿Por qué se actualizó el prototipo de admin1 cuando hice el método deleteUser(), pero por qué no se actualizó en absoluto cuando heredé User.prototype?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Me di cuenta de que cuando declaré deleteUser() simplemente estaba agregando al objeto prototipo de Admin, pero cuando heredé el prototipo de Usuario, reasigné completamente el prototipo de Admin. Por ejemplo, si declaro x = {a:1} podría hacer xb = 2 y luego x ahora es {a:1, b:2} . PERO si hago x = {a:1} y luego justo después de hacer x = {b:2} , reemplaza completamente el valor de x, no lo agrego.

about 4 years ago · Juan Pablo Isaza Report
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!