|
![](/i/fill.gif) |
Darren New wrote:
>>> window["foo"] = Function(){...}
>> OK. So in what way does this mean that "functions are not first-class"?
>
> I didn't say it did. I said that everything in Javascript is an object.
Correct, including functions themselves.
> There are no functions unassociated with a corresponding instance.
Functions are not associated with an instance when they are created, the
"association" is at call time.
var f = function (x) { return x; };
What instance is f associated to?
If you call f(4), 'this' inside the function body will be the global object
because of the way you *called* it. However:
var o = {};
o.f = f;
o.f(4);
This time, 'this' inside the function will be set to 'o'.
You can also do this:
var o = {};
f.call(o, 4);
Post a reply to this message
|
![](/i/fill.gif) |