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

315
Views
El enlace de función no funciona, devuelve indefinido

así que he creado dos objetos: persona y Tim.

Me gustaría vincular la función logInfo a Tim, pero cuando llamo a esto con vinculación, me sigue dando:

  1. trabajo indefinido
  2. telefono indefinido

Aquí está el código:

 function hello() { console.log('Hello') } const person = { firstNAme: 'A', age: 26, sayHello: hello, sayHelloWindow: hello.bind(document), logInfo: function (job, phone) { console.group(`${this.firstNAme} info: `) console.log(`name is: ${this.firstNAme} and the age is: ${this.age}`) console.log(`Job is: ${this.job}`) console.log(`Phone is: ${this.phone}`) console.groupEnd() } } const Tim = { firstNAme: 'Tim', age: 22 } const infoTim = person.logInfo.bind(Tim) infoTim('clown', '100100-10010') // returns undefined values, why?

¿Parece que me estoy perdiendo algo? ¡Gracias de antemano!

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

En la función logInfo , elimine this para job y phone , ya que se aceptan a través de argumentos y no son propiedad del objeto Tim . this siempre se refiere al objeto actual y this.something apunta a la propiedad del objeto.

Referir código actualizado

 function hello() { console.log('Hello') } const person = { firstNAme: 'A', age: 26, sayHello: hello, sayHelloWindow: hello.bind(document), logInfo: function (job, phone) { console.group(`${this.firstNAme} info: `) console.log(`name is: ${this.firstNAme} and the age is: ${this.age}`) console.log(`Job is: ${job}`) console.log(`Phone is: ${phone}`) console.groupEnd() } } const Tim = { firstNAme: 'Tim', age: 22 } const infoTim = person.logInfo.bind(Tim) infoTim('clown', '100100-10010')
about 4 years ago · Santiago Trujillo 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!