Backbone.js:`extend` 未定义? [英] Backbone.js: `extend` undefined?

查看:24
本文介绍了Backbone.js:`extend` 未定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚开始使用 Backbone.js.简单地包含 Backbone(开发/生产版本)会导致错误:

Just getting started with Backbone.js. Simply including Backbone (either dev/production versions) causes the error:

Uncaught TypeError: Cannot call method 'extend' of undefined 在第 128 行:

// Attach all inheritable methods to the Model prototype
_.extend(Backbone.Model.prototype, Backbone.Events, 

推荐答案

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

The issue was that I wasn't loading underscore.js. I totally missed that dependency in the docs. Duh.

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

Further clarification from @tjorriemorrie: I had underscore, but loaded in the wrong order, first load underscore (guess that is what 'dependency' means :)

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

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>

这篇关于Backbone.js:`extend` 未定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆