Question: how to access shortcut
or action
or other local variables
Related: Similar questions but not success:
- Passing local variable to loader anonymous handler function
- how to pass local variables when assigning mouseover via anonymous function?
- javascript anonymous function parameter passing
- How to pass variable to anonymous function
Java Solution:
set final
modifier to variables that required in anonymous function
Target Source code:
//plugin.buttons is collection of button objects
for (var i in plugin.buttons) {
var button = plugin.buttons[i];
var icon = button.icon;
var text = button.text;
var shortcut = button.shortcut;
var action = button.action; //action is a function ( or method )
if (shortcut != null && shortcut.length > 0) {
if ($.isFunction(action)) {
console.log(shortcut); //it's valid shortcut
//using jQuery hotkey plugin
$('div[contenteditable]').bind('keydown', shortcut, function () {
console.log(shortcut); //it's undefined
action.call(); //it's undefined also
return false;
});
}
}
}