views:

124

answers:

1

I have a singleton class based on Joose and I would like to add initialization arguments to it like this:

var programs = Programs.getInstance({
     tabContainer: '#tab'
 });

tabContainer is also declared as an attribute to the singleton.

In my after method modifier initialization method, I track to see if the arguments passed in was read like this:

 after: {
        initialize: function(){
             alert(this.getTabContainer());
        }
    }

But the alert produces the default value given, not the initialization value I passed to it.

Any idea how to pass arguments to the singleton in Joose?

I tested the same thing using regular class definitions in Joose and the above code alerts the proper argument.

+2  A: 

From the documentation for Joose about Singletons and Classes, the Class documentation specifically mentions this syntax as something that is supported. The Singleton documentation does not mention it. Most likely this is something that is not supported by Joose.

The problem with adding support for that to the Singleton is that the 2nd caller to the class may not have their initialization parameters applied since there can be only one instance of the class. Whoever invokes it first would have their parameters applied to it.

John Meagher
Ya, the Joose development team actually confirmed this too. I would be able to roll my own by using Roles.
Dhana