user1440625
user1440625

Reputation: 73

Using Backbone.js View as Require.js Dependency

How can I include a view from another file (e.g. Views.js) in a JavaScript file loaded as a Require.js module? I receive a "Uncaught TypeError: object is not a function" error when I try to instantiate myView.

define([
  'jQuery',
  'Underscore',
  'Backbone',
  'src/Views'
], function ($, _, Backbone, myView) {

  new myView ({ });
});

Upvotes: 0

Views: 316

Answers (1)

Justin wong
Justin wong

Reputation: 638

Do your "src/views.js" have a return value?

some like this:

define(['underscore', 'backbone'], function(_, Backbone) {
    var view = Backbone.View.extend({

        ......

    });
    return view; //the return value is essential
});

Upvotes: 1

Related Questions