user1724065
user1724065

Reputation:

Backbone view instantiation TypeError

I'm new to Backbone and I'm trying to get a basic view rendered using Underscore's templating. Here's the javascript:

TestView = Backbone.View.extend({
   initialize: function() {
      this.render();
   },
   render: function() {
      var template = _.template( $('#template').html(), {} );
      this.el.html( template );
   }
});

var test_view = new TestView( { el: $('#container') } );

This is the error I'm getting in Chrome:

Uncaught TypeError: Expecting a function in instanceof check, but got [object Object]

It's throwing the error from Backbone on line 1203 (development version). You can see the error in action at my website.

What am I doing wrong here? Should I omit the render() function?

Upvotes: 3

Views: 2437

Answers (1)

Juri
Juri

Reputation: 32900

Change the loading order, i.e. jQuery first:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="http://documentcloud.github.com/underscore/underscore.js"></script>
<script src="http://backbonejs.org/backbone.js"></script>

Upvotes: 12

Related Questions