Created
November 30, 2011 18:18
-
-
Save AlexJWayne/1410118 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::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() |
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 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