Backbone and AMD dependency definitions, parameters vs variables

I've been developing a Backbone app with different modules, and as it's now grown larger I'm looking to organise it with the AMD pattern and RequireJS.

I've been looking at different tutorials and articles about how to go about this, I've seen a couple of different ways to define the dependencies and was wondering: is there any major difference between these two Module definitions, I personally think the second is neater when it comes to a large amount of definitions?

define(function (require) {
           "use strict";

            var $           = require('jquery'),
                Backbone    = require('backbone'),
                Module1      = require('Module1'), 

                Employee = Backbone.Model.extend({

                    urlRoot: "/employees",

                    initialize: function () {
                        this.reports = new EmployeeCollection();
                        this.reports.url = this.urlRoot + "/" + this.id + "/reports";
                    }

                });

and:

define(['jquery', 'backbone', 'Module1'], function (jQuery, Backbone, Module1) {

           "use strict";

            var Employee = Backbone.Model.extend({

                    urlRoot: "/employees",

                    initialize: function () {
                        this.reports = new EmployeeCollection();
                        this.reports.url = this.urlRoot + "/" + this.id + "/reports";
                    }

                });

The first one got some drawbacks:

  • minifying is not available
  • defines can be scattered throughout the code, hiding dependencies
  • The second one is more readable and can be minified, but with many dependencies can produce really long lines and hard to trace pairs between the dependency name and the function input parameter.

    So if You need minification choose the second one, if it is not needed, choose the first.

    链接地址: http://www.djcxy.com/p/70412.html

    上一篇: Eventbus / Aggregator用于两个Requirejs应用程序

    下一篇: 主干和AMD依赖性定义,参数与变量