Skip to content

Instantly share code, notes, and snippets.

@Wizek
Forked from robotlolita/gist:1008428
Created June 4, 2011 22:43
Show Gist options
  • Save Wizek/1008445 to your computer and use it in GitHub Desktop.
Save Wizek/1008445 to your computer and use it in GitHub Desktop.
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