Skip to content

Instantly share code, notes, and snippets.

@fudini
Last active December 14, 2015 21:39
Show Gist options
  • Save fudini/5152757 to your computer and use it in GitHub Desktop.
Save fudini/5152757 to your computer and use it in GitHub Desktop.
/*
var Foo = Class.extend(function() {
this.var1 = "var1 foo";
});
var Bar = Foo.extend(function() {
this.var1 = "var1 bar"
console.log(this.super.var1); // access var1 from the base class
});
var foo = new Foo(); // base class
var bar = new Bar(); // sub class
A bit different:
var Foo = (function(Base) {
var staticPrivate = "static public";
var Foo = Base.extend(function() {
var private = "private";
this.public = "public"
});
Foo.staticPublic = "static public";
return Foo;
})(YourBaseClass);
*/
var Class = (function() {
var Class = function() {}
Class.extend = function(New) {
New.prototype = new this();
New.prototype.constructor = New;
New.prototype.super = New.prototype;
New.extend = arguments.callee;
return New;
}
return Class;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment