Error while creating a backbone.js view - Expecting a function in instanceof check, but got [object Object]
Solution 1
Basic things you should check out :
Wrap your new BodyView()
in jQuery.ready like this :
var BodyView = Backbone.View.extend({
el:$('body'),
initialize : function() {
console.log("view init");
}
});
$(function() {
new BodyView();
});
Load jQuery before Underscore and Backbone
Your script line for jquery should be before that of Backbone.
Your code actually works : http://jsfiddle.net/vTuPJ/
Solution 2
Works for me. Try to wrapper all the Backbone code in a documentReady
block:
$(function(){
// .. your backbone code
});
Another thing is that maybe you have to change the order of the scripts loads:
- underscore
- jquery
- backbone
Comments
-
user700284 almost 2 years
I am trying to create a simple backbone.js view with the following code:
<!DOCTYPE HTML> <html> <head> <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.3.1/underscore-min.js"></script> <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.2/backbone-min.js"></script> <!--<script type="text/javascript" src="http://ajax.cdnjs.com/ajax/libs/backbone.js/0.3.3/backbone-min.js"></script> --> <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script> </head> <body> <script type="text/javascript"> var BodyView = Backbone.View.extend({ el:$('body'), initialize : function() { console.log("view init"); } }); new BodyView(); </script> </body> </html>
But
I am getting an error Expecting a function in instanceof check, but got [object Object]
on this line -
new BodyView()
;This code is working if i use an older version of backbone.js(0.3.3)
Any idea why this error is happening and how to solve it?.Thanks in advance.
P.S - I have been mainly following http://backbonetutorials.com/what-is-a-view/ and http://documentcloud.github.com/backbone/#View for creating this sample backbone js app.