Coffeescript 调用coffescript超级方法

Coffeescript 调用coffescript超级方法,coffeescript,Coffeescript,我有以下代码: class Animal constructor: (@name) -> say: () -> console.log "Hello from animal called #{ @name }" class Dog extends Animal say: () -> super.say() console.log "Hello from dog

我有以下代码:

    class Animal
        constructor: (@name) -> 
        say: () -> console.log "Hello from animal called #{ @name }"

    class Dog extends Animal

        say: () ->
            super.say()
            console.log "Hello from dog called #{ @name }"

    a = new Animal('Bobby')
    a.say()

    d = new Dog("Duffy")
    d.say()            
结果并非如此

Hello from animal called Bobby
Hello from animal called Duffy
Hello from dog called Duffy
但我得到了以下错误:

Hello from animal called Bobby
Hello from animal called Duffy
Uncaught TypeError: Cannot call method 'say' of undefined

为什么super没有定义?如何调用父方法来扩展它?谢谢

我自己找到了答案,应该是:

class Dog extends Animal

    say: () ->
        super
        console.log "Hello from dog called #{ @name }"

这不应该是
super()
?@Ryan\u IRL调用super时不需要使用
()
。编译器可以告诉您,当您使用
super
关键字时,您正在调用函数。我想我们也应该能够传递参数。@Ziyan-如果基方法接受参数,您可以传递它:
super(“woof”)
。您的猜测是我的猜测。。。让我想知道为什么他们不让它像几乎所有人都猜到的那样工作?也许是一次有趣的讨论