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

185
Views
Objetos Javascript, constructores, ¿solo devuelven el valor final?

Estoy aprendiendo sobre objetos y constructores, así que creé un objeto para un libro.

Funciona bien después de algunas pruebas con un elemento (libro O autor O páginas O lectura), pero cuando agrego más de 1, solo devuelve el valor final.

Por ejemplo, lo siguiente solo devuelve "nope" cuando quiero que devuelva el title, author, pages, read (¿como pensé que declara mi función "bookInfo" ?

¿Qué me estoy perdiendo aquí ya que revisé mi código con algunos ejemplos y no puedo ver ningún problema?

 function Book(title, author, pages, read) { this.title = title this.author = author this.pages = pages this.read = read this.bookInfo = function() { return (title, author, pages, read) } } const LOTR = new Book('lord of the rings', 'JRR', '366', 'nope'); console.log(LOTR.bookInfo()); // should print 'lord of the rings', 'JRR', '366', 'nope') but only returns 'nope' (or whatever the last value is?)
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede devolver los valores asignados en una matriz:

 this.bookInfo = function() { return [this.title, this.author, this.pages, this.read]; }

u objeto:

 this.bookInfo = function() { return {title:this.title, author:this.author, pages:this.pages, read:this.read}; }

o cadena:

 this.bookInfo = function() { return `${this.title} ${this.author} ${this.pages} ${this.read}`; }
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!