Coffeescript:没有硬编码的实例方法的引用类方法

Mar*_* M. 22 coffeescript

以下面的代码为例:

class MyClass

  @staticMethod: -> hello_world()

  instanceMethod: -> MyClass.staticMethod()
Run Code Online (Sandbox Code Playgroud)

有没有办法从内部引用MyClass instanceMethod而不明确命名它?就像是self.staticMethod()

mu *_*ort 34

您可以constructor像在JavaScript中一样使用"类":

instanceMethod: ->
    @constructor.staticMethod()
Run Code Online (Sandbox Code Playgroud)

演示(添加了子类化以获得良好的衡量标准):http://jsfiddle.net/ambiguous/zM3ND/