1

I was wondering how I could load backbone plugins with require.js I currently have this in my main.js

(function() {
    'use strict';

    require.config({
    shim: {
        underscore: {
            exports: '_'
        },
        backbone: {
            deps: ['underscore', 'jquery'],
            exports: 'Backbone'
        },
        deepModel: {
            deps: ['underscore', 'backbone']
        }
    },
    paths: {
        jquery: 'lib/jquery/jquery',
        underscore: 'lib/underscore/underscore',
        backbone: 'lib/backbone/backbone',
        text: 'lib/requirejs-text/text',
        deepModel: 'lib/deep-model/deep-model.min'
    },

In my model I have something like this

var myapp = myapp|| {};
(function() {
    'use strict';

    define([
    'jquery',
    'underscore',
    'backbone',
    'deepModel',
    ], function($, _, Backbone) {

        myapp.model= new Backbone.DeepModel.extend({
            defaults: {
            },

            urlRoot: '/users',

For some reason the above does not seem to work as expected. I think I am missing something but not sure what that is. I am using the backbone deep model plugin.

This is the error I get in the debugger

Uncaught TypeError: Object [object Object] has no method 'apply'

1
  • You don't need to list libraries in your define statements which are dependencies of other libraries you are listing as dependencies, if the "transitive dependency" exports a variable to the global namespace. Commented Nov 12, 2013 at 21:34

2 Answers 2

2

Add DeepModel to your scope in function signature:

define([
'jquery',
'underscore',
'backbone',
'deepModel',
], function($, _, Backbone, **DeepModel**) 
Sign up to request clarification or add additional context in comments.

2 Comments

I still get the error Uncaught TypeError: Object [object Object] has no method 'apply' when I try to make an instance of my model.
what backbone version you use?
0

It might make your life easier if you use the AMD-compatible version of backbone and underscore. By default, they do not support AMD.

https://github.com/amdjs/backbone

https://github.com/amdjs/underscore

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.