107

Found this code back in jQuery 1.9.1. Checked again, and t is still here in jQuery 3.1.0. Suppose it is just in case the values of true and false ever change 😃

Comments
  • 15
    Assume nothing!
    Question everything!
  • 3
    but if the values of true and false change, these would return those new values? xD
  • 4
    @Swifticus Or do you mean "query everything"?
  • 4
    @StefanH I don't know anything about JS, but is it possible that it's for when you want to pass a function as an argument, but you always want it to return true or false in a corner case?
  • 3
    In languages like C, it is good practice to typedef commonly used native types. For example, instead of using "unsigned long", I might typedef that to "ULONG" and prefer to use that as my data type.

    The reason is for portability and to future-proof your code. If a native type doesn't use the same number of bits of memory on two different systems, or if a future compiler update somehow breaks previously-assumed truths about a native type, your whole program can easily be fixed by simply resolving the issue in the typedef.

    I realize that jQuery is nowhere near on the level of something like C, and I also realize that booleans are a fairly simple "type" to process...but this smells similar to me.
  • 12
    I think it's for minification purpose.

    return a(); is shorter than return false();
  • 1
    I'd it's so that those can be passed as callback functions.
  • 6
    They are used for assignments that need a function. For example:
    this.isDefaultPrevented = returnTrue;
    isDefaultPrevented is a function so it needs a function that returns true as the default functionality.
  • 0
    What wouldcyou say about 'function(x) { return x;}'? Looks even sillier, yet it isn't.
  • 0
    @icemad bet they could always return 1, 0, pr and of the other bool equivalents
  • 0
    @icemad good point, never thought about that.
Add Comment