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

199
Views
El enlace funciona cuando la función se asigna como propiedad, pero ¿por qué?

Estoy tratando de entender cómo funciona el enlace en Javascript y funciona el siguiente ejemplo. Pero cuando trato de usar this.numbers.map(this.doSomething) me da un error porque se está llamando estáticamente a doSomething . Para que funcione de nuevo tendré que usar el segundo ejemplo, pero no entiendo exactamente lo que está pasando. ¿Alguien tiene algunos enlaces/documentación que pueda usar para entender esto un poco mejor?

Primer ejemplo:

 export class SomeClass{ numbers = [1, 2, 3]; showNumber = (value: number) => console.log(`number is:`, value); processNumbers = () => { const a = this.numbers.map(b => this.doSomething(b)); // this gives me the error: 'showNumber' doesn't exist // const a = this.numbers.map(this.doSomething); // do something with a } private doSomething(value: number) { this.showNumber(value); } } const someClass = new SomeClass(); someClass.processNumbers();

Segundo ejemplo:

 export class SomeClass{ numbers = [1, 2, 3]; showNumber = (value: number) => console.log(`number is:`, value); processNumbers = () => { const a = this.numbers.map(this.doSomething); // do something with a } private doSomething = (value: number) => { this.showNumber(value); } } const someClass = new SomeClass(); someClass.processNumbers();
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!