Created
November 20, 2013 17:04
-
-
Save dmitry-vsl/7566867 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
include = (mixins...) -> | |
to: (clazz)-> | |
result = class extends clazz | |
for mxn in mixins | |
for own k,v of mxn(clazz) | |
result::[k] = v | |
result | |
# This is mixin. It can access methods of the class it is mixed to | |
TestMixin = (target) -> | |
foo: -> target::foo.apply @;console.log 'bar' | |
# define class with mixin. With requirejs it would be | |
# define [], -> | |
# include(TestMixin).to class | |
# foo: -> console.log 'baz' | |
Test = include(TestMixin).to class | |
foo: -> console.log 'baz' | |
someVar = new Test | |
someVar.foo() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment