On 10/17/06, Chris <[EMAIL PROTECTED]> wrote:
>
> Bob Ippolito wrote:
>
> > You're missing the point entirely. addLoadEvent takes a *function* as
> > an argument, and you're passing in the *result* of a function call.
>
> So then it's simply a matter of the existence of () or not at the end
> of the function name. When () is missing it passes the function as the
> argument. When () is present it executes the function in place per
> standard-programming-happenings.
>
> Ultimately it doesn't matter that I added an argument to the
> declaration but just that I tried to pass an argument at runtime.
>
> I just tested this idea and it appears to be true. Is there a name for
> this?
That's definitely not the way I'd describe it. It sounds like your
brain is conditioned to PHP or Perl land where there's a lot of
different syntax for different kinds of values... Nothing else in
common use that I'm aware of suffers from that particular kind of
brain damage.
In JavaScript there's no way to distinguish a function from anything
else at the source code level. A variable is just a name that refers
to some value at some point in time. That value may be a function, or
any other kind of object.
There are two kinds of syntax that invoke functions (not counting the
"new" operator):
// will invoke someExpression with "this" set to the global object
someExpression(arguments);
// will invoke someExpression['someMethod'] with "this" set to
someExpression
someExpression.someMethod(arguments);
Note that someExpression can be *any* expression. It does not have to
be a variable name... you can do something silly like this:
[function () { return 1; }][0]();
Which is equivalent to (in the order that JavaScript would do it):
var someFunction = function () { return 1; };
var someList = [someFunction];
var someExpression = someList[0];
someExpression();
The idea of allowing functions to be used interchangably as other
other value is called "higher order programming".
-bob
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"MochiKit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/mochikit
-~----------~----~----~----~------~----~------~--~---