我想通过使用mixin来拆分一个大类。
我正在使用Little Book中的这个mixin代码。
问题在于
我尝试在
我正在使用Little Book中的这个mixin代码。
@include: (obj) ->
for key, value of obj when key not in moduleKeywords
# Assign properties to the prototype
@::[key] = value
obj.included?.apply(@)
this
class FooMixin
b: => @something = 2
class Foo extends Module
@include FooMixin
a: => @something = 1
问题在于
FooMixin
中的@
是FooMixin
。我希望它变成Foo
。我尝试在
@include()
的结尾添加_.bind(@::[key], @)
,但没有帮助。有什么建议吗?
extend
的方法,这将与此处描述的方法冲突。如果你发现自己遇到了各种问题,请尝试将其重命名为其他名称--这对我很有效。 - Chris Salzberg