{"snip":"function Singleton (argument) {\n // the cached instance\n var instance;\n\n // rewrite the constructor\n Singleton = function Singleton(argument) {\n return instance;\n };\n \n // carry over the prototype properties\n Singleton.prototype = this;\n\n // the instance\n instance = new Singleton();\n\n // reset the constructor pointer\n instance.constructor = Singleton;\n\n // code ...\n\n return instance;\n}","mode":"javascript","fileName":"Singleton"}

Reply to this note

Please Login to reply.

Discussion

No replies yet.