Singletons
A singleton class is one which can only ever have one instance. The concept is
more useful in Java, where you cannot create an object without first creating
a class. JavaScript allows objects without classes (indeed, it has no classes,
only objects) but using JS.Singleton lets you create custom objects from
existing JS.Class classes, allowing you to inherit methods, include modules
and use method() et al.
var Camel = new JS.Singleton(Animal, {
fillHumpsWithWater: function() { ... }
});
// You can call instance methods...
Camel.speak('the desert'); // from Animal
Camel.fillHumpsWithWater();
var s = Camel.method('speak');
s('drinking');
Camel.klass.superclass // -> Animal
JS.Singleton just creates a class with the arguments you give it,
immediately instantiates this new class and returns the instance. You can
access the class through Camel.klass as shown above.