1

Getting an error:

Uncaught TypeError: undefined is not a function

Anonymous function error is pointing to

Backbone.history.start()

Below is my index.html and main.js.

I have a feeling, the jquery,underscore and backbone files may not be loading properly,due to which this error is happening Kind of beginner in backbone.Any help is greatly appreciated

versions used:

underscore - 1.8.3
backbone - 1.1.2

index.html

<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <link rel="stylesheet" href="/stylesheets/style.css">
        <script src="javascripts/jquery.min.js"></script>
        <script src="javascripts/json2.js"></script>
        <script src="javascripts/underscore-min.js"></script>
        <script src="javascripts/backbone-min.js"></script>
        <script src="javascripts/main.js"></script>
    </head>
</html>

main.js

    $(document).ready(function(){

    var Theater = {
        Models: {},
        Collections: {},
        Views: {},
        Templates:{},
        Routers:{}
    }

    Theater.Models.Movie = Backbone.Model.extend({});


    Theater.Collections.Movies = Backbone.Collection.extend({
        model: Theater.Models.Movie,
        url: "/json",
        initialize: function(){
            console.log("Movies initialize")
        }
    });


    Theater.Routers = Backbone.Router.extend({
        initialize:function(){  console.log("defaultRoute");},
        routes: {
            "": "defaultRoute" 
        },
        defaultRoute: function () {
            console.log("defaultRoute");
        }
    });

    console.log("gonna call approuter");
    var appRouter = new Theater.Routers();
    Backbone.history.start();

   });
Deenadhayalan Manoharan
  • 5,436
  • 14
  • 30
  • 50
dreamer
  • 901
  • 2
  • 15
  • 38
  • you should click the line it's referring to in console. It might offer a bit more information as to the exact line (if applicable) – Seth Apr 10 '15 at 13:25
  • @Seth : yea, i did that and that's how i got to understand Backbone.history.start() is having some problem :) – dreamer Apr 10 '15 at 13:40
  • So the line it's referring to is `Backbone.history.start()`? You should try putting a breakpoint on it and stepping through all the functions calls to see where it's breaking. – Seth Apr 10 '15 at 14:35

1 Answers1

0

My guess is you're probably using a pretty old version of jQuery, 1.6 maybe?

1.6 doesn't include the on method for listening to events, so I'd guess that when you call Backbone.history.start(), Backbone throws an error when it tries to do:

Backbone.$(window).on('hashchange', this.checkUrl);

Upgrade your version of jQuery. If you need to support IE 6/7/8 upgrade to jQuery 1.x, if not upgrade to 2.x.

garethdn
  • 12,022
  • 11
  • 49
  • 83