I want to use goog.addSingletonGetter() (http://closure-library.googlecode.com/svn/!svn/bc/4/trunk/closure/goog/docs/closure_goog_testing_singleton.js.source.html#line56) to add a getInstance() method to a class with a constructor that accepts arguments:
Foo = function(x, y) {...};
Is there a way for me to specify goog.addSingletonGetter(Foo, arg1, arg2)? Calls to Foo.getInstance() would then lazily return the instantiated Foo object.
Closure: The Definitive Guide on page 70 defines
goog.addSingletonGetter()as follows:One approach would be to create a singleton following the Instance in a Static Property design pattern presented in JavaScript Patterns on page 143 with the addition of a static
getInstance()function.The advantage to using this pattern is that it protects you from accidentally constructing multiple instances in the event that someone were to write: