I've seen lots of similar questions, but feel like I'm still missing something. I have the following code:
_setHotKeys: function(values, buttons){
var hotKeyMap = {
target: document,
binding:[]
};
values.forEach(function(value, index){
if(value.hotkey){
this.button = buttons[index];
hotKeyMap.binding.push({
key: value.hotkey,
fn: function(key, event){
this._handleFillInValueButtonToggle(this.button, true);
},
scope: this
});
}
}, this)
var keyMap = new Ext.util.KeyMap(hotKeyMap);
},
In this function I am trying to set up hotkeys using Ext.js. This code will set up a hotkey for each of the values in the value
array, but they all set this.button
to the last button in the buttons
array. My conclusion is that it is pushing a reference to this.button
rather than the value into the array, so as the loop progresses, this value changes. How can I set it to push the value instead of the reference?