Coffeescript 有没有一种方法可以以更像咖啡脚本的方式扩展原型?

Coffeescript 有没有一种方法可以以更像咖啡脚本的方式扩展原型?,coffeescript,prototype,underscore.js,marionette,Coffeescript,Prototype,Underscore.js,Marionette,通常,在使用Coffee脚本时,我会向Backbone.marionete.Application添加方法,就像这样 do (Backbone) -> _.extend Backbone.Marionette.Application::, testMethod: -> console.log "I was here" 我想知道是否有一个更“咖啡脚本”的方式来做到这一点。IE使用extends关键字,而不使用下划线extend。正如您所写,没有可用于扩展应用程

通常,在使用Coffee脚本时,我会向Backbone.marionete.Application添加方法,就像这样

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

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

正如您所写,没有可用于扩展应用程序的对象,但如果您想创建“子类化”对象,可以执行以下操作

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

这基本上就是@mu在他的评论中所建议的。

为什么不将
Backbone.marionete.Application子类化呢?Monkey patching很简洁,但它不应该是你接触到的第一个工具。之前关于使用Coffeescript
extends
与主干
extend
的讨论。与Backbone.marionete.Application::testMethod=->console.log相比有什么优势“我在这里?”