Backbone.js: `extend` undefined?
Solution 1
The issue was that I wasn't loading underscore.js
. I totally missed that dependency in the docs. Duh.
Further clarification from @tjorriemorrie: I had underscore, but loaded in the wrong order, first load underscore (guess that is what 'dependency' means :)
Further Clarification just in case this isn't obvious. The order that things are loaded in JavaScript relates to the order the show up on the page. To load underscore first, be sure that the script tag including it comes before the one loading backbone. Like this:
<script src="underscore-1.4.4-min.js"></script>
<script src="backbone-1.0.0-min.js"></script>
Solution 2
Backbone only hard dependency is Underscore.js load underscorejs script before backbonejs script
Solution 3
The order is also important. I got the same error and it was was not resolved until I gave the underscore.js before backbone.js.
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.3.3/underscore-min.js" type="text/javascript"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.2/backbone-min.js" type="text/javascript"></script>
Related videos on Youtube
Matt Darby
I've developed on the web for 17 years. I can configure pools of servers, architect and develop the applications on those servers, and make it all look good (and run). I am a Professor at Franklin University, hold a Master's in Computer Science and I lead 500 members of the Columbus Ruby Brigade. I've launched projects for folks from Rackspace, AT&T, Sprint, LivingSocial and SeoMoz to local engineering and consulting firms. I currently work at Rackspace as a Developer Advocate. It rules.
Updated on July 08, 2022Comments
-
Matt Darby almost 2 years
Just getting started with Backbone.js. Simply including Backbone (either dev/production versions) causes the error:
Uncaught TypeError: Cannot call method 'extend' of undefined
on Line 128:// Attach all inheritable methods to the Model prototype _.extend(Backbone.Model.prototype, Backbone.Events,
-
Victor Farazdagi over 12 yearsThank you so much, was puzzled what I am doing wrong, and why I can't even load the backbone!
-
Tjorriemorrie about 12 yearsI had underscore, but loaded in the wrong order, first load underscore (guess that is what 'dependency' means :)
-
Xeoncross almost 12 years4,600+ views and 55 upvotes later it seems lots of people are missing the requirements. Perhaps they should be more pronounced.