On Tue, Nov 2, 2010 at 6:59 PM, Sean McArthur <[email protected]>wrote:
> I was going to recommend the approach you just mentioned, OR... Not really
> using a class at all.
>
> When having Singletons, I tend to just create an object literal. If you
> want the singleton to be able to fire events, just extend Events.
>
> var Moobox = {
>
> };
>
> Object.extend(Moobox, new Events);
>
>
I Agree. Not everything is a nail. Class was meant to give us specific
tools, especially a constructor method that can be inherited. If you
instantiate on creation, and you want to disable the new operator, there's
no better way than simply not have a constructor at all.
>
> On Tue, Nov 2, 2010 at 8:56 AM, stratboy <[email protected]> wrote:
>
>> Hi thank you all @Ryan and Arieh.
>>
>> > Singletons
>> >
>> > There's Christoph's Class.Singleton, I've never used it though:
>> >
>> > http://github.com/cpojer/mootools-class-extras
>>
>> If you think that I should use a singleton, then I'm going to use some
>> natural js methods that are described here:
>>
>>
>> http://keetology.com/blog/2009/07/23/up-the-moo-herd-iii-its-classy-not-classic
>>
>> In particular, I really like this one, using a closure:
>>
>> (function(){
>>
>> // variable for holding the instance..
>> var instance = null;
>>
>> this.Singleton = new Class({
>>
>> initialize: function(name){
>> if (instance) return instance;
>> instance = this;
>> }
>> });
>> })();
>>
>> Bye! :)
>>
>>
>>
>>
>>
>>
>
--
Arieh Glazer
אריה גלזר
052-5348-561
5561