Hi everyone,

My question is--  quite often I do something like this:

var Photos = (function() {
    var Photos = Class.create({
        initialize: function() {
                var photos = this;
//............etc
    }

return Photos;
})();

and then when I have class methods, I have redefine a local variable
to reference the class, such as:

       foo: function() {
          var photos = this;
}

I prefer to set a variable to 'this', because the context of this ends
up getting very confusing at times, and requires lots of .bind,
etc..... So anyway, doing the whole 'var photos = this' in every
method ends up being rather redundant and so I have found myself
doing:

var Photos = (function() {
    var Photos = Class.create({
        initialize: function() {
                photos = this;
         // etc
        },

        foo: function() {
          photos.do_something;
        }
    });

   return Photos;

})();

So this solves that problem-- but global variables are "evil"..
BUT..  this is in the context of a closure, so I wonder if it's less
evil?  Or if there is a better way to do what I am doing?  I am not
sure how you guys do this sort of thing...  So, I'd love to hear your
advice.

Thanks.
-patrick

-- 
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.

Reply via email to