English 中文(简体)
3. 初步确定意见之前的必要法律文件
原标题:RequireJS loads scripts before the view is initialized

I have a Backbone view as a requirejs module. The problem is that requirejs load the http://localhost/remote/script/here.js before the view is even initialized. Is it because the script isn t inside a requirejs module?

define([
     jquery ,
     undescore ,
     backbone ,
     http://localhost/remote/script/here    
], function($, _, Backbone, Luajs){
    var View = Backbone.View.extend({
        initialize : function(options) {
        },
        render : function() {
            this.$el.html( <p>my view</p> )
            return this;
        }
    });

    return View;
});
最佳回答

The array you have as the first argument to define is the depedencies of your view. So yes it is loaded and parsed before the View. Also note that unless you use modified versions of backbone and underscore, they ar not AMD compliant. You will need to wrap them with a plugin to load them properly.

问题回答

you try to define the view Backbone after the load the module. You can do this, in the define () method of RequireJS. The array of this function contains parameters that defines module dependencies.





相关问题
How to handle circular dependencies with RequireJS/AMD?

In my system, I have a number of "classes" loaded in the browser each a separate files during development, and concatenated together for production. As they are loaded, they initialize a property on a ...

RequireJS - Loading an already loaded module

I am trying to use RequireJS to load browser modules and I came into an interesting problem. I have 3 modules named a, b and c having these simple source code: a.js define([ ./b , ./c ], function(...

Understanding when and how to use Require.JS

I ve just begun to work with Require.JS and I m a bit unclear on the appropriate cases in which it should be used, as well as the correct way to use it in those cases. Here s how I currently have ...

RequireJS traditional script loading aka Order Plugin

I have been beating my head against this for quite a while. I m loading about 60 script files that need to respect a certain dependency structure. Loading these normally in requirejs does not work, ...

热门标签