Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught ReferenceError: Backbone is not defined

I am completely new to Backbone JS. I thought I could solve this minor problem by myself but I can't figure why I am still getting this error:

Uncaught ReferenceError: Backbone is not defined

when trying to extend a Backbone.Model. backbone.js is called before the script that uses it so I don't get it.

index.html

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8"/>
        <script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
        <script type="text/javascript" src="js/backbone.js"></script>
        <script type="text/javascript" src="js/main.js"></script>
        <title></title>
    </head>
    <body>

    </body>
</html>

My external file main.js

(function($) {
    window.Doc = Backbone.Model.extend({
        defaults : {
            id : '???',
            title : 'Le titre de mon modèle',
            text : 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer varius ipsum nec porta dignissim. Donec a elementum magna. Donec sagittis magna eu nulla ullamcorper dictum. Interdum et malesuada fames ac ante ipsum primis in faucibus. Nullam volutpat felis vehicula, congue mi at, lobortis dolor.',
            keywords : 'lorem ipsum dolor sit amet'
        },
        initialize : function Doc() {
            console.log('Doc Constructor');
        }
    });
})(jQuery);

I also get the following error coming from backbone.js:219

Uncaught TypeError: Cannot call method 'each' of undefined

like image 922
D4V1D Avatar asked Dec 01 '22 02:12

D4V1D


1 Answers

You forgot to import underscore.js. It is a Backbone requirement.

Grab it here!

like image 148
LudovicL Avatar answered Dec 04 '22 09:12

LudovicL