Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: a.apply is not a function

I am following a backbone.js for beginners tutorial, and I've got stuck at the first hurdle. I get the error TypeError: a.apply is not a function in firebug (Firefox 20.0.1). I have the following code:

<!DOCTYPE html>
<html lang="en">
<head>
<title>Backbone Test</title>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.1.1/css/bootstrap.min.css" />
<meta charset="utf-8" />
</head>
<body>

    <div class="container">
        <h1>User Manager</h1>
        <hr />
        <div class="page"></div>
    </div>

    <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.8.2/jquery.min.js" type="text/javascript"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.2/underscore-min.js" type="text/javascript"></script>   
    <script src="//cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.2/backbone-min.js" type="text/javascript"></script>
    <script>
        var Router = new Backbone.Router.extend({
            routes: {
                '': 'home'
            }    
        });

        var router = new Router();

    </script>

</body>
</html>

I am using these older versions of jquery, underscore and backbone because they are the versions used in the tutorial. I tried using current versions of all, and I get a similar error: "TypeError: i.apply is not a function".

The error happens when an instance of Router is created, ie the line: var router = new Router(); above.

Is the error to do with my set-up? WAMP, or the code, or the libraries? I can't understand it as it's the same to the letter as the tutorial.

like image 313
dewd Avatar asked Apr 30 '13 12:04

dewd


1 Answers

Change

    var Router = new Backbone.Router.extend({

To

    var Router = Backbone.Router.extend({

When you're extending those classes, you only need to invoke extend, which will return the constructor function that you'll call new on later.

like image 199
Rob Hruska Avatar answered Oct 07 '22 12:10

Rob Hruska