I have a Backbone Marionette application with a module defined below. When I run this application, the console log statement prints out @
as the window object. When the list
method is run, I thought that this
(@
) would refer to the List.Controller
object. What am I missing?
###
The Header list controller.
###
define [
'cs!app',
'cs!./view',
'cs!modules/header/entities'
], (
App,
View
) ->
App.module 'Header.List', (List, App, Backbone, Marionette, $, _) ->
List.Controller =
list: ->
console.log(@)
headers = App.request 'header:entities'
view = new View.Headers {collection: headers}
App.headerRegion.show view
setActiveHeader: (headerUrl) ->
headers = App.request 'header:entities'
header = headers.find (header) -> (header.get 'url') == headerUrl
header.select()
headers.trigger 'reset'
App.commands.setHandler 'header:setActive', (headerUrl) ->
List.Controller.setActiveHeader headerUrl
App.Header.List.Controller
Update
This is the module that calls the list method:
###
The Header module.
###
define [
'cs!app',
'cs!./list/controller'
], (
App,
listController
) ->
App.module 'Header', (Module, App, Backbone, Marionette, $, _) ->
Module.startWithParent = false
App.module 'Routers.Header', (ModuleRouter, App, Backbone, Marionette, $, _) ->
class ModuleRouter.Router extends Marionette.AppRouter
appRoutes: {}
executeAction = (action, args) ->
action(args)
API =
list: ->
executeAction listController.list
App.Header.on 'start', ->
API.list()
App.addInitializer ->
new ModuleRouter.Router {listController: API}
App.Header