A
aum
Hi,
For the benefit of folks coming from other languages such as Python, I've
created a small framework that simplifies the creation and use of classes,
subclasses and instances.
http://www.freenet.org.nz/js/classframework.html
Features:
- freely mix classical and prototypal inheritance
- can wrap traditional javascript 'constructor function' classes
- more familiar feel to those coming in from other languages
- facilitates somewhat more readable code (IMHO)
So instead of having to use weird idioms like:
function F(arg) {
this.arg = arg;
}
F.prototype.toString = function() {
return "[F:arg="+this.arg+"]"
}
function G() {
F.apply(this, arguments)
}
G.prototype = new F()
G.prototype.toString = function() {
return "[G:arg="+this.arg+"]"
}
f = new F("foo")
g = new G("bar")
you can now do:
F = Class.subclass({
init: function(arg) {
this.arg = arg;
},
toString: function() {
return "[F:arg="+this.arg+"]"
}
})
G = F.subclass({
toString: function() {
return "[G:arg="+this.arg+"]"
}
})
f = F.instance("foo")
g = G.instance("bar")
Cheers
aum
For the benefit of folks coming from other languages such as Python, I've
created a small framework that simplifies the creation and use of classes,
subclasses and instances.
http://www.freenet.org.nz/js/classframework.html
Features:
- freely mix classical and prototypal inheritance
- can wrap traditional javascript 'constructor function' classes
- more familiar feel to those coming in from other languages
- facilitates somewhat more readable code (IMHO)
So instead of having to use weird idioms like:
function F(arg) {
this.arg = arg;
}
F.prototype.toString = function() {
return "[F:arg="+this.arg+"]"
}
function G() {
F.apply(this, arguments)
}
G.prototype = new F()
G.prototype.toString = function() {
return "[G:arg="+this.arg+"]"
}
f = new F("foo")
g = new G("bar")
you can now do:
F = Class.subclass({
init: function(arg) {
this.arg = arg;
},
toString: function() {
return "[F:arg="+this.arg+"]"
}
})
G = F.subclass({
toString: function() {
return "[G:arg="+this.arg+"]"
}
})
f = F.instance("foo")
g = G.instance("bar")
Cheers
aum