I can’t help but notice there are two seemingly useless functions in the source code of jQuery (For v1.9.1, it’s line 2702 and line 2706):
function returnTrue() {
return true;
}
function returnFalse() {
return false;
}
Which both are called quite often within jQuery. Is there a reason why they don’t simply substitute the function call with a boolean true or false?
it was used like this:
here
isImmediatePropagationStoppedis a query method. used like thisevent.isImmediatePropagationStopped()of course, you can define a instance method, like:
but you have to introduce a new instance property
_isImmediatePropagationStoppedto store the status.with this trick, you can cut off bunch of instance properties for hold true/false status here, like
_isImmediatePropagationStopped,_isDefaultPreventedetc.so that, in my opinion, this is just a matter of code style, not right or wrong.
PS: the query methods on event, like
isDefaultPrevented,isPropagationStopped,isImmediatePropagationStoppedare defined in DOM event level 3 sepc.spec: http://www.w3.org/TR/2003/NOTE-DOM-Level-3-Events-20031107/events.html#Events-Event-isImmediatePropagationStopped