If I have this:
$(SomeID).on({
click: function () { SomeFunction1(); },
mouseenter: function () { SomeFunction2(); },
mouseleave:function () { SomeFunction3(); }
}, '.SomeClass');
I can rewrite it as
$(SomeID).on({
click: SomeFunction1,
mouseenter: SomeFunction2,
mouseleave: SomeFunction3
}, '.SomeClass');
But what if I need to pass some parameter like this:
$(SomeID).on({
click: function () { SomeFunction1($(this)); },
mouseenter: function () { SomeFunction2($(this).index()); },
mouseleave: function () { SomeFunction3($(this).index()); }
}, '.SomeClass');
Is there an alternative?
Thanks.
As @Jashwant says, the same
thiswould be used in the function anyway, so it’s the one value you don’t need to worry about (in your example).Note that you could do as you describe if you needed to, it’s easy for static values, and is called currying. A javascript example would be: http://www.dustindiaz.com/javascript-curry/