How to reproduce this error with a minimum number of lines:
<html> <body> <script type="text/javascript"> var AppView = Backbone.View.extend({ }); </script> <div>mydiv</div> </body> </html>
You get an error message:
ReferenceError: Backbone is not defined var AppView = Backbone.View.extend({
You have not included the required core libraries.
If you get this error, run this Hello world example:
This example defines the reference base:
<html> <body> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script> <script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.3.3/underscore-min.js" type="text/javascript"></script> <script src="http://cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.2/backbone-min.js" type="text/javascript"></script> <div>Loading...</div> <script type="text/javascript"> alert("starting backbone"); var AppView = Backbone.View.extend({ el: 'div', initialize: function(){ alert("initializing backbone"); this.render(); }, render: function(){ alert("applying text to div attribute"); this.$el.html("Hello World"); } }); var appView = new AppView(); alert("done"); </script> </body> </html>
To run this example in jsfiddle, see here: http://jsfiddle.net/ZfnbK/
It should show 4 popups illustrating the path that it takes through the code. When the rendering function is called, backbone uses jQuery to replace the contents of the div: "Hello World" tag.
source share