Skip to content

Instantly share code, notes, and snippets.

@AlexJWayne
Created November 30, 2011 18:18
Show Gist options
  • Select an option

  • Save AlexJWayne/1410118 to your computer and use it in GitHub Desktop.

Select an option

Save AlexJWayne/1410118 to your computer and use it in GitHub Desktop.
Function::include = (otherClass) ->
for name, method of otherClass::
this::[name] = method
return
class Bar
b: -> console.log 'b'
class Foo
@include Bar
a: -> console.log 'a'
x = new Foo()
x.a()
x.b()
var Bar, Foo, x;
Function.prototype.include = function(otherClass) {
var method, name, _ref;
_ref = otherClass.prototype;
for (name in _ref) {
method = _ref[name];
this.prototype[name] = method;
}
};
Bar = (function() {
function Bar() {}
Bar.prototype.b = function() {
return console.log('b');
};
return Bar;
})();
Foo = (function() {
function Foo() {}
Foo.include(Bar);
Foo.prototype.a = function() {
return console.log('a');
};
return Foo;
})();
x = new Foo();
x.a();
x.b();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment