Backbone.js:“扩展”未定义?
刚刚开始使用 Backbone.js。简单地包含 Backbone(开发/生产版本)会导致错误:
第 128 行上的 Uncaught TypeError: Cannot call method 'extend' of undefined
:
// Attach all inheritable methods to the Model prototype
_.extend(Backbone.Model.prototype, Backbone.Events,
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,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
问题是我没有加载
underscore.js
。我完全错过了文档中的依赖关系。呃。@tjorriemorrie 的进一步澄清:
我有下划线,但加载顺序错误,首先加载下划线(猜测这就是“依赖关系”的意思:)
进一步澄清,以防万一这并不明显。 JavaScript 中加载内容的顺序与页面上显示的顺序相关。要首先加载下划线,请确保包含下划线的脚本标记位于加载主干的脚本标记之前。像这样:
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:
Backbone 唯一的硬依赖是 Underscore.js
在backbonejs脚本之前加载underscorejs脚本
Backbone only hard dependency is Underscore.js
load underscorejs script before backbonejs script
顺序也很重要。我遇到了同样的错误,直到我在backbone.js之前给出underscore.js后才解决。
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.