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
I found the answer myself, it should be:
class Dog extends Animal say: () -> super console.log "Hello from dog called #{ @name }"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With