与
upperclass = class Superclass
constructor: () ->
@somemethod: () ->
console.log "I'm in super"
@someothermethod: () ->
console.log "I'm trying to reach super without going through sub!"
@somemethod()
lowerclass = class Subclass extends Superclass
constructor: () ->
@somemethod: () ->
console.log "I'm in sub but only want to go to super! I.e. not through sub, calling super here!"
@someothermethod: () ->
super
lowerclass.someothermethod()
我希望 @somemethod 调用直接转到 super 方法,避免使用子方法。那可能吗?将 @ 添加到一些方法声明中,使其与 CoffeeScript 测试器一起使用 here .
最佳答案
您可以直接引用Superclass.somemethod
:
Superclass.somemethod.call @
我认为在不命名父类(super class)
的情况下不可能(或没有必要)做到这一点。
关于javascript - 来自 sub 时直接调用其他 super 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32338315/