Take an argument, and then see if there is instanceof jQuery.Event :
function yourFunction(e) { if (e instanceof jQuery.Event) {
Live example | A source
I would recommend avoiding this kind of thing. Instead, I would recommend that the event handler call the target function (instead of using the target function as the actual event handler) if you need to distinguish between behavior depending on how it was called.
From the comment to the question:
I just tried: when the function is called directly, I use a null value in the first position and a useful argument in the second position.
In this case, it is even simpler:
function yourFunction(e) { if (e) {
You don't even need to pass null to a function, just call it without arguments. When you do this, e will be undefined , which is false. (The jQuery event object that passes the handler will never be false.)
source share