有没有办法以更方式的咖啡脚本扩展原型?

时间:2014-01-02 21:06:21

标签: coffeescript prototype underscore.js marionette

通常,在使用Coffee Script时,我将方法添加到Backbone.Marionette.Application,就像这样......

do (Backbone) ->
  _.extend Backbone.Marionette.Application::,
    testMethod: ->
      console.log "I was here"

我想知道是否有更多的“咖啡脚本”方式来做到这一点。 IE使用extends关键字而不使用下划线扩展。

1 个答案:

答案 0 :(得分:2)

正如你所写的那样,没有任何对象可以扩展你的应用程序,但如果你想创建一个对象'子类',你可以做类似的事情

class MyApp extends Backbone.Marionette.Application
  testMethod: -> console.log "I was here"

这基本上是@mu在评论中提出的建议。

相关问题