Sander B Sander B -4 years ago 163
CoffeeScript Question

Call an overwritten method in coffeescript

I want to call a method (foo) in Coffee-script from a subclass. I know I can do this with

@foo
if I didn't overwrite foo in the subclass, or with super if I did overwrite it and I'm calling from the subclass' foo method.

However, I would like to call superclass' foo method from subclass bar method. How can this be done?

Answer Source

Not sure why you need this but ...

class A
  foo: ->
    console.log 'A'

class B extends A
  foo: ->
    console.log 'B'
  bar: ->
   A::foo.call @

new B().bar()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download