Backbone.js:“扩展”未定义?

发布于 2024-10-15 23:09:34 字数 284 浏览 1 评论 0原文

刚刚开始使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

时光礼记 2024-10-22 23:09:34

问题是我没有加载 underscore.js。我完全错过了文档中的依赖关系。呃。

@tjorriemorrie 的进一步澄清:
我有下划线,但加载顺序错误,首先加载下划线(猜测这就是“依赖关系”的意思:)


进一步澄清,以防万一这并不明显。 JavaScript 中加载内容的顺序与页面上显示的顺序相关。要首先加载下划线,请确保包含下划线的脚本标记位于加载主干的脚本标记之前。像这样:

<script src="underscore-1.4.4-min.js"></script>
<script src="backbone-1.0.0-min.js"></script>

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>
浅唱々樱花落 2024-10-22 23:09:34

Backbone 唯一的硬依赖是 Underscore.js
在backbonejs脚本之前加载underscorejs脚本

Backbone only hard dependency is Underscore.js
load underscorejs script before backbonejs script

往事风中埋 2024-10-22 23:09:34

顺序也很重要。我遇到了同样的错误,直到我在backbone.js之前给出underscore.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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文