0

TodoMVCのBackbone+RequireJSバージョンを理解しようとしています。main.jsファイルでバックボーンパッケージが依存関係にない理由がわかりませんか?

// Require.js allows us to configure shortcut alias
require.config({
    // The shim config allows us to configure dependencies for
    // scripts that do not call define() to register a module
    shim: {
        'underscore': {
            exports: '_'
        },
        'backbone': {
            deps: [
                'underscore',
                'jquery'
            ],
            exports: 'Backbone'
        }
    },
    paths: {
        jquery: 'lib/jquery/jquery.min',
        underscore: '../../../assets/lodash.min',
        backbone: 'lib/backbone/backbone',
        text: 'lib/require/text'
    }
});

require([
    'views/app',
    'routers/router' // <--views/app.js and routers/router.js are the only dependencies
], function( AppView, Workspace ) {
    // Initialize routing and start Backbone.history()
    new Workspace();
    Backbone.history.start(); // <--Here we use Backbone variable. Where do the writer tell the page about the backbone dependency??

    // Initialize the application view
    new AppView();
});
4

1 に答える 1

0

バックボーンは shim 構成によってグローバルとしてエクスポートされるため、依存関係を定義する必要はありません。これは、グローバル名前空間で既に使用できるためです。

詳細については、 http://requirejs.org/docs/api.html#config-shimを参照してください。

于 2012-09-28T15:34:42.293 に答える