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

210
Views
¿Cuál es la mejor manera de verificar si un objeto es un prototipo de otro?

Creo que la mejor manera sería algo como:

 var a = {a:1, b:2} var b = Object.create(a); ba = 1 var c = Object.create(b); cc = 3; var d = Object.create(c); d.protoTree(); //returns: [c, b, a] c.protoTree(); //returns: [b, a]; b.protoTree(); //returns: [a];

¿Pero es esto posible? ¿Cuál es la mejor manera de asumir que solo conoces el objeto D?

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

0

Puede usar isPrototypeOf() para este caso de uso

about 4 years ago · Juan Pablo Isaza Report

0

Si no sería bueno tener eso como un método miembro, pero es fácil de implementar como una función independiente (recursiva):

 function protoTree(obj){ if(obj === null) return [] return [obj, ...protoTree(Object.getPrototypeOf(obj))] }

Funciona así (tenga en cuenta que también devuelve Object.prototype , del que hereda a .

 var a = {a:1, b:2} var b = Object.create(a); ba = 1 var c = Object.create(b); cc = 3; var d = Object.create(c); //Note that `protoTree` returns the prototype objects themselves, not the variable names they are stored in protoTree(d); //returns: [c, b, a, Object.prototype] protoTree(c); //returns: [b, a, Object.prototype] protoTree(b); //returns: [a, Object.prototype] protoTree(a); //returns: [Object.prototype]
about 4 years ago · Juan Pablo Isaza Report

0

Usar Object.prototype.isPrototypeOf() es la forma de hacer esto

 function Person() {} function Child() {} Child.prototype = Object.create(Person.prototype); const child = new Child(); console.log(Person.prototype.isPrototypeOf(child)); console.log(Child.prototype.isPrototypeOf(child));

Más sobre Object.prototype.isPrototypeOf() aquí

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!