Michael Geary schrieb:
> Now, for some odd syntactic reason, you can't say:
> function() {}(); // error!
>
> But remember that foo() and (foo)() are the same thing. So you can throw
> some parens around the function:
>
> ( function() {} )(); // calls the function
>
Hey Mike,
could you che
Michael Geary <[EMAIL PROTECTED]> wrote:> See if this helps:>> function Stuff() {> // do stuff> }>> var stuff1 = new Stuff(); // call the Stuff constructor
> var stuff2 = new Stuff; // parens are optionalThanks, the "aha!" light just went on. It makes total sense now...I didn't know
Michael,
Thanks, exactly what i needed.
Will
>>> Yes, as others mentioned, ( function() { /*stuff*/ } )();
>>> will do the trick too, and is slightly more efficient.
>>>
>
>
>> is there somethign special about ( ... )(); ? I mean, how
>> does this come from another example?
>>
>
Will, it's the only way (until JS1.7) to declare local variables...
normally JS variables are not allocated in the scope you might guess,
they are allocated at the function level, even if they are deeply
nested.
On 9/27/06, Will Jessup <[EMAIL PROTECTED]> wrote:
> Michael,
>
> comments inside
> >
John,
Last night I downloaded Firefox 2 rc1.
It has let... and lots more js 1.7 stuff to bad it will take time
til MS (et al) catch up!
On 9/27/06, John Resig <[EMAIL PROTECTED]> wrote:
> Todd -
>
> You're correct, it's used to induce a contained scope.
>
> This was a technique that, if I r
> > Yes, as others mentioned, ( function() { /*stuff*/ } )();
> > will do the trick too, and is slightly more efficient.
> is there somethign special about ( ... )(); ? I mean, how
> does this come from another example?
There's nothing special about it. Any time you have a reference to a
funct
Michael,
comments inside
>> Here's a pattern that occurs frequently that I'm really
>> curious about:
>>
>> new function() {
>>// do stuff
>> }
>>
>> Is the purpose of this just to provide local scope to the
>> variables used?
>>
>
> Yes, that is the one and only reason for it.
>
>
Hi,
> John, I think there is one difference between both techniques.
>
> While in
>
> new function() {
>
> }
>
> the this keyword points the "anonymous" object itself, in
>
> (function() {
> ...
> })();
>
> it does not. Right?
The first technique not only creates a new context but also the '
> Here's a pattern that occurs frequently that I'm really
> curious about:
>
> new function() {
>// do stuff
> }
>
> Is the purpose of this just to provide local scope to the
> variables used?
Yes, that is the one and only reason for it.
> Is there an equivalant syntax that may be
> mor
Hi,
> but new function() { ... }; is much cleaner, IMO. As far as I know,
> that is the "best" way to have a local scope, [...]
We had that before. Deans way to create a local scope ((function() {...})())
is better, because it doesn't create a new Object that you never use. Of
course that diffe
John Resig schrieb:
> Todd -
>
> You're correct, it's used to induce a contained scope.
>
> This was a technique that, if I remember correctly, I learned from
> Dean Edwards (http://dean.edwards.name/) I use to use:
>
> (function(){
>...
> })();
>
> but new function() { ... }; is much cle
Todd ,
From my understanding its partly for variable scoping, partly for
garbage collection and part of a pattern to emulate classes. I did a
posting of the full pattern here: http://www.willjessup.com/?p=35
Will
> Hello,
> I've been poking around a bit in the jQuery source code. It's been
>
Todd -
You're correct, it's used to induce a contained scope.
This was a technique that, if I remember correctly, I learned from
Dean Edwards (http://dean.edwards.name/) I use to use:
(function(){
...
})();
but new function() { ... }; is much cleaner, IMO. As far as I know,
that is the "best
Hello,I've been poking around a bit in the jQuery source code. It's been enlightening and has proven that I don't know as much about _javascript_ as I thought I did!Here's a pattern that occurs frequently that I'm really curious about:
new function() { // do stuff}Is the purpose of this just to p
14 matches
Mail list logo