Reputation: 12324
I'm wondering why this works with jquery hotkeys:
$(document).bind('keydown', 'm', dothis);
but this doesn't:
$(document).bind('keydown', 'm', dothis(6));
Even like this doesn't work:
$(document).bind('keydown', 'm', dothis());
Upvotes: 0
Views: 52
Reputation:
You can also use curried function. Its function which returns function.
function doThis (num) {
return function () {
// Do something with num
}
}
$(document).bind('keydown', 'm', dothis(6))
Upvotes: 0
Reputation: 1948
You must give the binding a function as a parameter.
In the second and third cases you are giving a function call which gets evaluated, and the returned value is given to the keybind function - presumably you do not return a function and that does nothing.
If you want to construct a new function with set parameters from a function you already have, use bind:
$(document).bind('keydown', 'm', dothis.bind(null, 6));
Upvotes: 2