A static class is totaly usefull when you have a widget that will always have one instance and is linked to a object.
Fábio Miranda Costa Engenheiro de Computação http://meiocodigo.com On Sun, May 10, 2009 at 8:00 PM, nwhite <changereal...@gmail.com> wrote: > @christoph I agree the benefits of having a Singleton pattern in javascript > are extremely limited. When developers are first introduced to OO paradigms > they typically fall in love with Singletons for all the wrong reasons. With > that said I do think there are a few use cases where it could prove > advantageous. The registry pattern comes to mind, under this use case still > being able to write your code 'new Registry' provides for more explicit code > and helps with debugging, this is strictly a style and seperation issue. > Another place where I see a use is in a Lazy Load Delegation model where the > delegators have no awareness of each other. In this case the Dispatcher is > only initalized when needed and after such initiation is avaliable for all > other delegators. > > I would argue with your rational that we don't have Singletons or Statics > in javascript. The implementation may not look identical to other languages > but I never read anywhere that it had to be implemented a specific way, it > just had to follow a particular pattern. If we are going to nit pick that > said features don't belong in Javascript which for the most part I do agree > with you, I also question the need for private/protected methods in classes. > > > > > On Sun, May 10, 2009 at 3:17 PM, Christoph Pojer < > christoph.po...@gmail.com> wrote: > >> >> Remember that we don't have Singletons nor do we have "static classes" >> in a prototype-based language. So this is basically a mix of all of >> those approaches. I just don't see the use of a real Singleton pattern >> in JavaScript anyway. You either have a simple Object ( var MyObject = >> {} ) or an instance of a Class (with the new new Class way) - there >> clearly is no need for a real singleton pattern :) >> >> On May 10, 9:56 pm, Fábio Costa <fabiomco...@gmail.com> wrote: >> > This looks like a static class more than the singleton pattern. >> > >> > Fábio Miranda Costa >> > Engenheiro de Computaçãohttp://meiocodigo.com >> > >> > On Sun, May 10, 2009 at 4:31 PM, Christoph Pojer >> > <christoph.po...@gmail.com>wrote: >> > >> > >> > >> > > As JavaScript doesn't really have the concept of a Singleton I think >> > > the easiest way to use it is just to do something like var MySingleton >> > > = new new Class({ ... }). This creates a class and directly one single >> > > instance of it. Of course, you can't subclass it or use the new >> > > operator with it again, but thats not the point here :) >> > >> > > On May 7, 5:16 pm, Paul Spencer <pagam...@gmail.com> wrote: >> > > > anyone successfully tried nwhite's singleton mutator [1] with the >> > > > latest mootools? I'd love to use it but it doesn't seem to be >> working >> > > > for me using the example provided ... I tried to follow the code to >> > > > see if I could figure out what is going wrong, but its beyond me in >> my >> > > > present uncaffeinated state of mind :( >> > >> > > > Cheers >> > >> > > > Paul >> > >> > > > [1] >> http://www.nwhite.net/2008/10/10/mootools-singleton-class-mutator/ >> > >> > >> > >