문제

I'm trying to follow the example code that i've seen here and several other places for loading backbone/underscore with require.js. i've basically copy/pasted the example code from Loading Backbone and Underscore using RequireJS but it isn't working.

in app.js the alert(Backbone) displays, Backbone is null. I'm not really sure why it isn't there - can anybody see what i'm doing wrong? thanks for any help.

index.html

<script type="text/javascript" data-main="scripts/main" src="scripts/require.js"></script>

scripts/main.js

require.config({
    paths: {
        'jquery': 'libs/jquery-1.7.1',
        'underscore': 'libs/underscore', 
        'backbone': 'libs/backbone'
    }
});

require([
    'libs/domReady',
    'app/app'
], function(domReady, app){
    domReady(function () {
        app.initialize();
    });
});

scripts/app/app.js

define([
    'jquery', 
    'underscore',
    'backbone'
], function($, _, Backbone){
    return {
        initialize: function(){
            // examples say you can use $, _ or Backbone here
            // but Backbon is null here...  WTF???
            alert(Backbone);
        }
    };
});

Here's the versions I have in case that's important: jquery 1.7.1 require.js version 1.0.4 underscore 1.3.0 backbone version 0.5.3 modelbinding 0.4.3

도움이 되었습니까?

해결책

Can we see your file structure, with file names? is your backbone file @ libs/backbone.js? or is it libs/backbone-0.5.3.js or something? same goes for underscore and other libraries, the name has to be correct.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top