zetter
zetter

Reputation: 5

Why am I getting a type error when trying to instantiate an empty backbone.js view?

I am in the process of learning backbone.js and have written some very simple code.

I am getting an error when executing the following line:

var myView = new View();

Here is the error in Firebug:

TypeError: i is not a function  

When I comment out that line there is no error (of course... no view object either).

Here is the code:

<body>
<script type="text/javascript">

        var Model        = Backbone.Model.extend({});       
        var Collection   = Backbone.Collection.extend({});
        var View         = Backbone.View.extend({});

        var myModel      = new Model();
        var myCollection = new Collection();
        var myView       = new View();

</script>
</body>

My question is:

Why do myModel and myCollection instantiate properly, but myView does not?

Thanks for your help.

Upvotes: 0

Views: 297

Answers (1)

Derick Bailey
Derick Bailey

Reputation: 72858

You're missing Underscore or jQuery in your HTML script references.

Backbone requires Underscore.js, and should be used with either jQuery or Zepto for DOM manipulation. Specifically with view instantiation, you need either jQuery or Zepto.

Your HTML file should include those files in the right order:

<script src="/path/to/jquery.js"></script>
<script src="/path/to/underscore.js"></script>
<script src="/path/to/backbone.js"></script>

Upvotes: 1

Related Questions