考虑这个例子:
class Parent
@staticMethod = ->
#calleeConstructor = ????
new calleeConstructor().x
class Child1 extends Parent
constructor: ->
@x = 10
class Child2 extends Parent
constructor: ->
@x = 20
#Usage
Child1.staticMethod() #Should return 10
Child2.staticMethod() #Should return 20
是否可以?
例如,我知道我可以从父实例方法访问原始类的其他一些静态成员或构造函数。我的意思是:
class Parent
instanceMethod: -> @constructor.staticVar
class Child1 extends Parent
@staticVar = 10
class Child2 extends Parent
@staticVar = 20
#Usage
console.log new Child1().instanceMethod() #Should return 10
console.log new Child2().instanceMethod() #Should return 20