Last active
December 14, 2015 21:39
-
-
Save fudini/5152757 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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