I've got an event handler in JavaScript that I'd like to overload:
function overloadedHandler(event, myObject){
if(event){
var elem = event.currentTarget;
} else {
var elem = myObject.x;
}
//function logic
}
$('.mydiv').on('click', overloadedHandler);
If I want to call the overloadedHandler from another function (not as an event handler), what's the right way to do it?
overloadedHandler(null, obj);overloadedHandler(undefined, obj);overloadedHandler(false, obj);
P.S. I understand that I could put //function logic part in another function & call that when needed outside of an event handler, but I would like to know if there's anything wrong with the above approach?
overloadedHandler({currentTarget: obj.x});.