Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Instantly share code, notes, and snippets.

@yoko
Created January 26, 2009 12:27
Show Gist options
  • Save yoko/52801 to your computer and use it in GitHub Desktop.
Save yoko/52801 to your computer and use it in GitHub Desktop.
Simple class based on Ten.Class.
Class = function(prototype, base) {
var c = prototype.initialize || (
base ?
function() { return base.apply(this, arguments); } :
function() {}
);
c.prototype = prototype;
c.prototype.constractor = c;
if (base) {
c.SUPER = base;
c.prototype.SUPER = base.prototype;
Class.extend(base, c);
Class.extend(base.prototype, c.prototype);
}
return c;
};
Class.extend = function(base, self) {
for (var k in base)
if (typeof self[k] == 'undefined' && k != 'initialize')
self[k] = base[k];
return self;
};
/*
Foo = new Class({
initialize: function(a) { // constractor
this.a = a;
},
run: function() {
return this.getA();
},
getA: function() {
return this.a;
}
});
foo = new Foo('a');
foo.run(); // a
Foo2 = new Class({
initialize: function(a, b) {
this.constractor.SUPER.call(this, a);
this.b = b;
},
run: function() {
return this.getA() + this.getB();
},
getB: function() {
return this.b;
}
}, Foo);
foo2 = new Foo2('a', 'b');
foo2.run(); // ab
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment