While I think you are coming down a little harsh on the guy, I do have to agree. I am still trying to figure out how that code is enforcing a singleton pattern.
Further, why is everyone still reinventing this stuff. This has all been solved and is in almost every framework.
Take for example my personal favorite, Dojo I would wrap all of this functionality up into a widget that an HTML developer (or myself) could just use a tag to implement e.g
then the Dojo JavaScript object associated with the widget would have a routine that connects to the onclick event to do the following:
dojo.style("backgroundColor", this.newColor);
That's it, I never code it again. I understand if you are doing this a personal enrichment, but if you are doing this to complete a job task, you should really leverage existing code, this includes code that you and others have already written.
Further, why is everyone still reinventing this stuff. This has all been solved and is in almost every framework.
Take for example my personal favorite, Dojo I would wrap all of this functionality up into a widget that an HTML developer (or myself) could just use a tag to implement e.g
<a href="..." dojoType="my.namespace.BackgroundChangeHREF" newColor="#CCCC00">a link</a>
then the Dojo JavaScript object associated with the widget would have a routine that connects to the onclick event to do the following:
dojo.style("backgroundColor", this.newColor);
That's it, I never code it again. I understand if you are doing this a personal enrichment, but if you are doing this to complete a job task, you should really leverage existing code, this includes code that you and others have already written.