My code is this:
$('button#submit-order').on('click', () => orderPanelInfo.hide());
I'm wondering if it's possible to do same operation like this:
$('button#submit-order').on('click', orderPanelInfo.hide);
My code is this:
$('button#submit-order').on('click', () => orderPanelInfo.hide());
I'm wondering if it's possible to do same operation like this:
$('button#submit-order').on('click', orderPanelInfo.hide);
What you're doing (the arrow function) is fine provided the browsers you're targeting support them (otherwise, just use a normal function). The other alternative is to use Function#bind
but it involves repeating yourself:
$('button#submit-order').on('click', orderPanelInfo.hide.bind(orderPanelInfo));
// -----------------------------------------------------^^^^^^^^^^^^^^^^^^^^^
Function#bind
was added in 2009 so only Really Truly Obsolete browsers have JavaScript engines that don't have it (and it can be polyfilled on them if necessary).