0
votes

I have the following code that is being included (the code is generated from CoffeeScript):

console.log('test1');

application.module('core', function(module, application, Backbone, Marionette, $, _) {
  console.log('test2');
  return module.TodoItem = (function(_super) {

    __extends(TodoItem, _super);

    function TodoItem() {
      return TodoItem.__super__.constructor.apply(this, arguments);
    }

    return TodoItem;

  })(Backbone.Model);
});

Looking at https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.application.module.md is seems to me that this code should work however is seem like the function for the core module never gets executed (test1 prints to the console however test2 does not). Is there something I am missing?

1

1 Answers

3
votes

An module's definition function won't get executed until the module is started. That happens either by calling application.start() and letting the app start all of your modules, or by calling application.module('core').start() to start the module directly.

Two other notes:

  1. There's no need to return module.TodoItem... you can just assign module.TodoItem = ... and it will be made available on the application.core namespace.

  2. It looks like your TodoItem is just extending from Backbone.Model. It would be more backbone-idiomatic to do module.TodoItem = Backbone.Model.extend({...}).

I'm guessing by the structure of this JavaScript, and the two items I just pointed out, that you're using CoffeeScript to generate this? If so, ignore those two items as you won't be able to change them.