3 ms·
I guess it doesn't hurt to have it, especially if you're writing a lot of singletons, but it just seems strange to me to do it explicitly since singletons are e
by Jebdm 18y ago
I guess it doesn't hurt to have it, especially if you're writing a lot of singletons, but it just seems strange to me to do it explicitly since singletons are extremely easy to implement in prototype-based languages.
singleton = Object()
singleton.x = 0
singleton.foo = function(){
return x + 1
}
Edit: Also, why not http://www.prototypejs.org/ http://www.prototypejs.org/ ? Not that there's anything wrong with playing around with stuff of course.
- jmtulloss 18y agoI agree, that's what I do now. Adding them is purely for consistency in syntax (sugar, if you will). Using this library, there is a syntactic consistency between declaring types and singletons that you don't have normally. I use prototype on a day to day basis and I'm not a huge fan. Mootools has captured my attention as being a better alternative, and some of the code was taken from mootools. This is just classes though, not a full JS library.