如何在coffeescript中重写父方法,同时仍然能够调用父方法
我有两个像这样的咖啡脚本课程。在基础视图模型中,我希望在继承自基础视图模型的子对象中覆盖一个方法如何在coffeescript中重写父方法,同时仍然能够调用父方法,coffeescript,Coffeescript,我有两个像这样的咖啡脚本课程。在基础视图模型中,我希望在继承自基础视图模型的子对象中覆盖一个方法 class exports.BaseViewModel constructor: () -> someBaseMethod: => console.log "I'm doing the base stuff" class ChildViewModel extends BaseViewModel constructor: () ->
class exports.BaseViewModel
constructor: () ->
someBaseMethod: =>
console.log "I'm doing the base stuff"
class ChildViewModel extends BaseViewModel
constructor: () ->
someBaseMethod: =>
@doSomethingFirst()
super @someBaseMethod()
这不起作用,因为行super@someBaseMethod()
调用自己创建了一个无限循环
有可能在这里实现我想要的吗?是的,像调用函数一样调用
super
(它表示对所使用方法的超类版本的引用):
可能重复的
class ChildViewModel extends BaseViewModel
constructor: ->
someBaseMethod: =>
@doSomethingFirst()
super()