我想在我的新项目 Coffee + Marionette + Require.js 中使用,但我遇到了模块加载查询的问题。模块会在主应用启动回调后启动;
# main.coffee
require.config
paths:
# ...
app: '/js/app/app'
marionette: '/js/vendors/backbone.marionette'
shim:
# ...
'marionette':
deps: ['backbone']
exports: 'Marionette'
'app':
deps: ['marionette']
exports: 'App'
require ['app'], (App) ->
App.start()
# module.coffee
define ['app'], (App) ->
MyModule = App.module('MyModule');
MyModule.foo = ->
console.log 'bar'
return MyModule
# app.coffee
define (require) ->
App = new Marionette.Application
App.addInitializer ->
require 'module'
console.log 'App inited'
App.on
'start': ->
console.log 'App started'
return App
# Output
App inited
App started
Module inited
如果我想在初始化程序中使用他,我必须如何定义模块?