Calling coffescript super methods

Viewed 13919

I have the following code:

    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()            

The result is not

Hello from animal called Bobby
Hello from animal called Duffy
Hello from dog called Duffy

But I get the following error:

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

How come super is undefined? How to call a parent method in order to extend it? Thanks

1 Answers
Related