javascript - Calling prototype method from another method -


i trying call prototype method jquery event handler. have code this:

$('#' + this.id + ' .selmake').on('change', this.getcarmodel()); 

i error saying: uncaught typeerror: object [object global] has no method 'getcarmodel'

what doing wrong here?

use code:

vehicleselect.prototype.getcarmakes = function() {   // optional parameters   var options = {};    var select = $('#' + this.id + ' .selmake'),       = this;    select.on('change', function(e) {     that.getcarmodel();   });    // callback function called when api response returned   function success(res) {     (var i=0; i<res.makes.length; i++) {       $("<option>",{         value: res.makes[i].nicename,         html: res.makes[i].name       }).appendto(select);     }     select.removeattr("disabled");     select + $(' option[value="placeholder"]').html('select make');   }   // oops, have problem!   function fail(data) { console.log(data); }   // fire api call   this.res.api('/api/vehicle/v2/makes', options, success, fail); }; 

for why can't use select.on('change', this.getcarmodel) see this question (which provides alternative solutions).


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -