From: Hubert Kauker on
On Jul 30, 2:39 am, Jesse <imje...(a)gmail.com> wrote:
>
> myNamespace =  {}; //namespace for holding any objects/functions
>
> //helpModule as an example
> myNamespace.HelpModule = new (function(){
>     this.abc = '123';
>     //lots of other code in here...
>     return this;
>
> })();

What we have here is the application of the 'new' operator to an
anonymous constructor function.
Seems entirely legitimate to me and not at all obscure.

However, I would drop the 'return' statement inside the body.

--
Hubert

From: Ry Nohryb on
On Aug 9, 10:13 am, Hubert Kauker <hubert.kau...(a)travelbasys.de>
wrote:
> On Jul 30, 2:39 am, Jesse <imje...(a)gmail.com> wrote:
>
> > myNamespace =  {}; //namespace for holding any objects/functions
>
> > //helpModule as an example
> > myNamespace.HelpModule = new (function(){
> >     this.abc = '123';
> >     //lots of other code in here...
> >     return this;
>
> > })();
>
> What we have here is the application of the 'new' operator to an
> anonymous constructor function.
> Seems entirely legitimate to me and not at all obscure.

It's not too obscure, but IMO this is better (clearer):

myNamespace.HelpModule= {};
myNamespace.HelpModule.abc= "123";
myNamespace.HelpModule.aMethod= function(){ ... };
....etc

> However, I would drop the 'return' statement inside the body.

Yep, it's not needed.

The (function () {})() pattern is being used too often gratuitously,
for no reason, such as in this FAQ entry:
http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/b9aede5baeb64755#

var numberToFixed =
(function() {
return toFixedString;
(...)
--
Jorge.
From: Ry Nohryb on
On Aug 9, 10:13 am, Hubert Kauker <hubert.kau...(a)travelbasys.de>
wrote:
> On Jul 30, 2:39 am, Jesse <imje...(a)gmail.com> wrote:
>
>
>
> > myNamespace =  {}; //namespace for holding any objects/functions
>
> > //helpModule as an example
> > myNamespace.HelpModule = new (function(){
> >     this.abc = '123';
> >     //lots of other code in here...
> >     return this;
>
> > })();
>
> What we have here is the application of the 'new' operator to an
> anonymous constructor function.
> Seems entirely legitimate to me and not at all obscure.

Ah, and that extra () at the end aren't wanted: it should be new
function(){}; or new (function(){}); but not new (function(){})();
--
Jorge.
From: Evertjan. on
Garrett Smith wrote on 09 aug 2010 in comp.lang.javascript:

> Of all possible arguments could have been made, that one is truly lousy.
>
> Specification terminology is absolutely appropriate for posts on
> comp.lang.javascript.

Arguments in this NG's terminology are the parameters of a function.

;-)

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
From: williamc on
On 7/29/2010 11:59 PM, David Mark wrote:
> On Jul 29, 11:38 pm, RobG <rg...(a)iinet.net.au> wrote:
>> On Jul 30, 10:39 am, Jesse <imje...(a)gmail.com> wrote:
>>

....

>> A function's this keyword has nothing to do with scope, it is a
>> reference to an object. It is set by the call to the function, you
>> can't control it by how you create the function other than by limiting
>> how it is called.
>
> Thanks for picking that up. Somehow I missed that offending use of
> the term. It seems to be so pervasive that virtually every developer
> who uses the "major" libraries thinks that scope is the - this -
> object; which leaves the question of what they would call the concept
> of scope (if they are even aware of the concept).
>

Well, what is the correct way to think about scope in Javascript? I tend
to think of it as

global
|_ function
|_ inner function
|_ inner, inner function
|_ etc...

but that's probably naive.

--

--williamc