Cobra: A Little JavaScript Class Library
justin.harmonize.fm
justin.harmonize.fm
Admittedly, others might not run into these situations, but it's happened to me frequently enough to include it.
singleton = Object()
singleton.x = 0
singleton.foo = function(){
return x + 1
}
Edit: Also, why not http://www.prototypejs.org/ ? Not that there's anything wrong with playing around with stuff of course.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.
var singleton = function (args) {
/*object constructor stuff*/
}(arg-values)I talk a bit more about what I'm trying to fix earlier: http://justin.harmonize.fm/index.php/2008/12/a-better-object...
self.cats = [new Tiger(), new Tiger(), new Cat()];
Instead of:
this.cats = [new Tiger(), new Tiger(), new Cat()];
?
It's vaguely interesting looking at how he did it, the actual output itself, not so much. You'd be better off reading Doug's Javascript the Good Parts than trying to remake your Javascript into something it's not.
If you look at the code, it uses prototypical inheritance. The whole thing is very lightweight, under 200 lines of code.
I do love "JavaScript the Good Parts", but I do have some issues with the syntactic inconsistencies that exist in JS, good parts or not.
A single line assignment already seems quite shortcutish to me...