javascript - Why does this variable reference not work? -
this.prefixmonday[0] exists @ current scope this.prefixmonday array of 3 checkboxes within initcomponent method of extend of panel
this.weekdays = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday']; for(var = 0; i<7; i++){ this['prefix' +this.weekdays[i] +'[0]'].on('check',this.somefunction, this); }
firebug says can't find: this['prefix' +this.weekdays[i] +'[0]']
i'm pretty sure have acces
this['prefix' +this.weekdays[i]][0]
otherwise javascript search key string 'prefixmonday[0]' , don't think want. make more readable might want use helper variable store name:
for(var = 0; i<7; i++){ var key = 'prefix' +this.weekdays[i]; this[key][0].on('check',this.somefunction, this); }
Comments
Post a Comment