Backbone.js: `extend` undefined?
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
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 🙂
<script src="underscore-1.4.4-min.js"></script> <script src="backbone-1.0.0-min.js"></script>
Backbone only hard dependency is Underscore.js
load underscorejs script before backbonejs script
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.