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

231
Views
¿Por qué obtengo 'this.XXXXX is not a function' cuando es una función?

Tengo el siguiente código. Todo lo que quiero hacer es hacer un trabajo diferente según el valor del botón de opción seleccionado, y estoy usando onclick.

/*html*/

 <input label='radio' id='radioYes' name='selectionA' value='yes'> <input label='radio' id='radioNo' name='selectionA' value='no'>

/* Javascript */

 (function(){ var obj = { start: function(){ /* Do some work */ this.addEvents(); /* Do some work */ }, addEvents: function(){ document.getElementById('radioYes').onclick = function() {this.radioClicked(true);}; document.getElementById('radioNo').onclick = function() {this.radioClicked(false);}; }, radioClicked: function(bool){ if(bool){ /*Yes was selected. Do some work.*/ } else{ /*No was selected. Do some work.*/ } } }; obj.start(); }();

Cuando hago clic en el botón de TypeError: this.radioClicked is not a function pero no puedo entender por qué. ¡La función 'radioClicked' se define justo debajo!

Cuando hago lo siguiente sin ningún parámetro, funciona bien.

 addEvents: function(){ document.getElementById('radioYes').onclick = this.radioClicked; document.getElementById('radioNo').onclick = this.radioClicked; }, radioClicked: function(){ /* Do some work */ }

Leí en algún sitio web que si desea pasar parámetros, puede poner su función dentro de una función anónima como hice en el primer código que no funciona. ¿Podría alguien ayudarme con lo que estoy haciendo aquí?

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!