From http://stackoverflow.com/a/15196301/:
p.s. i'll be glad to hear you solution to my other question stackoverflow.com/questions/15274927/…. ( maybe you have a better solution). Royi Namir 2013-03-08 07:03:32Z
The answers do include good examples of both eagerly-loaded/instant (e.g., jantimon, SLaks) and lazy-loaded singletons (e.g., Kolink).
Though, for a few variations on lazy-loaded: :)
It is possible to return
the instance
(single-instance-constructor.js
) each time, but this will probably be confusing unless it's not actually new
(constructor-as-function.js
). :)
A possible ES5+ variant would be to use a get-only "static" property (readonly-static-property.js
).