0
votes

In the book "Structuring Backbone Code with RequireJS and Marionette Modules" by Sulc D. there is a code: define(["app", "apps/config/storage/localstorage"], function(ContactManager){ ContactManager.module("Entities", function(Entities, ContactManager, Backbone, Marionette, $, _){ Entities.Contact = Backbone.Model.extend({ urlRoot: "contacts", .....

ContactManage is a backbone.Marionette app instance

var ContactManager = new Marionette.Application();
  1. For waht I know from requirejs documentation, we should define dependencies in ["app", "ContactManager"...] and pass App and ContactManager in function(App, ContactManager ...), but in the above code ContactManager is passed to function, but it is not defined as a dependency. Why is it so?

  2. Please, also explain, what this code does:

    ContactManager.module("Entities", function(Entities, ContactManager, Backbone, Marionette, $, _){

Why should we create a requirejs module? Thanks!!!

full code: https://github.com/davidsulc/structuring-backbone-with-requirejs-and-marionette/blob/master/assets/js/entities/contact.js

code is available in guthub https://github.com/davidsulc/structuring-backbone-with-requirejs-and-marionette

1

1 Answers

0
votes
  1. Since "app" is the first declared dependency, it will be the first parameter passed into the function. In the above code, the first parameter of the function is 'ContactManager'. Therefore, ContactManager IS the app for the scope of this function.

  2. The module declaration line creates a new module named 'Entities'. Outside the scope of that declaration, the module can be referenced as ContactManager.Entities. The book has a good explanation of why modules are useful. Most notably, they can be stopped and started as necessary, freeing up memory where possible.