Created
June 4, 2011 22:27
-
-
Save robotlolita/1008428 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
function inherits(ctor, base) { | |
ctor.prototype = Object.create(base); | |
ctor.prototype.constructor = ctor | |
return ctor | |
} | |
function extend(tgt) { var sources | |
sources = Array.prototype.slice.call(arguments, 1) | |
sources.forEach(function(source){ | |
Object.keys(source).forEach(function(key){ | |
tgt[key] = source[key] })}) | |
return tgt | |
} | |
function with_traits(){ var traits | |
traits = Array.prototype.slice.call(arguments) | |
return function(tgt) { | |
return extend.apply(this, [tgt].concat(traits)) } | |
} | |
inherits(ClassJS, SomeParentObject) | |
function ClassJS() { | |
/* constructor initialization */ | |
} | |
extend(ClassJS.prototype, function(){ | |
return with_traits(trait1, trait2, trait3) | |
({ foo: foo | |
, bar: bar }) | |
function foo() { /* ... */ } | |
function bar() { /* ... */ } | |
}()) | |
var instance = new ClassJS | |
instance.foo() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment