The Wayback Machine - https://web.archive.org/web/20150419080153/https://code.google.com/p/joose-js/wiki/Singletons
My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
Singletons  
How to create Singletons with Joose
Updated Feb 4, 2010 by malte.ubl

Joose provides a standard role to build singletons. Just use does: [Joose.Singleton] in a class definition to declare your class to be a singleton. Your class will receive a clas method getInstance() that returns the instance. You will no longer be able to create instances with the new operator.

Example

    Class("MySingleton", {
        does: [Joose.Singleton],
    
        has: {
            test: {
                init: function () { return [] }
            }
        }
    })

    var single = MySingleton.getInstance();
Comment by [email protected], Jun 12, 2011

Hi,

I can't access my Singleton from a Class within the same module using m.MySingleton?.getInstance() - inspecting this value shows only proto

Comment by [email protected], Jun 12, 2011

google code ruins my post: it was supposed to be two underscores before and after "proto"


Sign in to add a comment
Powered by Google Project Hosting