On May 5, 1:53 pm, Matt Kruse <m...@thekrusefamily.com> wrote:
> On May 5, 3:38 pm, kiusau <kiu...@mac.com> wrote:
>
> > QUESTION: If a lone pair of parentheses can be used to automatically
> > call a function, then what does it mean when two pairs are juxtaposed
> > in the same statement as follows: ()(jQuery);?
>
> See, this is purely a javascript language question, unrelated to
> jQuery specifically.
>
> In js, () around something simply returns what is inside of it. So, (x)
> ===x.
>
That is not entirely true, as the statement:-
x(true);
should be a interpreted as call operation, the stuff inside of the
parens is an ArgumentList in that case.
() - can be:
* a grouping operator
* an "Arguments" expression (for use with a [[call]] or
[[construct]] operation).
* part of the production for a function definition, as function(){}
(and also a JS 1.8 "expression closure"[1], a non-standard language
extension).
> Then,
>
> (function() { })
Grouping Operator.
>
> simply returns the anonymous function object. And how do you call a
> function? You put () after it.
>
> (function() { })();
>
Calling a function. The "Arguments" can also be used for construct, or
"new":-
var time = new (function(x){
this.timeStamp = +new Date;
this.end = new Date(x); // Invalid Date.
})(Infinity);
[...]
Garrett