On Jul 27, 3:30 am, Wilkins <[email protected]> wrote:
> The project I'm working on has an enormous JS file that I didn't want
> to add to. I wanted to access some of the methods defined, so I
> created an adapter file that would load "after" (minfied + combined)
> the main file.
>
> Here is how the original would look:
> var APP = APP || {};
> APP = {
>         stuff : {
>                 doStuff : function(){},
>                 doStuffAgain : function(){}
>         },
>         moreStuff : {
>                 doMoreStuff : function(){}
>         }
>
> };
>
> In order to access it's methods, I returned it as an object like this:
> var APP = APP || {};
> APP = (function() {
>         return {
>                 stuff : {
>                         doStuff : function() {
>                         },
>                         doStuffAgain : function() {
>                         }
>                 },
>                 moreStuff : {
>                         doMoreStuff : function() {
>                         }
>                 }
>                 // etc
>         };
>
> })();

Wrapping the object in an anonymous function that just returns the
object is a complete waste of time. All it does is call a function to
return the original object.

The only benefit of that pattern (the module pattern) is to use
closures for "private" members or keep functions designed to be used
internally private (i.e. not available as public members).


> It seems to work fine.

Becaue all you are doing is calling a function to return the same
object.


> I have access to everything I need in my
> adapter. However, there were never any tests written, so I'm not 100%
> sure EVERYTHING will work.
> Are there any obvious downsides in doing something like this?

Only that it creates a useless function and likely a lot of unused
closures (which may or may not be an issue). And it's pointless.

A better question is "Are there any benefits?", to which the answer
is: none.


--
Rob

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to