未定义是不是在Backbone.js的功能 [英] Undefined is not a function in Backbone.js

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

问题描述

我得到的错误未定义是不是一个函数本地和从Dropbox的公共URL运行此code时,的 http://dl.dropbox.com/u/6862628/backbone.html

I get the error "undefined is not a function" when running this code locally and from a Dropbox public url, http://dl.dropbox.com/u/6862628/backbone.html.

不过,当我的jsfiddle它按预期运行它: http://jsfiddle.net/fdKKD/

However, when I run it on jsfiddle it works as expected: http://jsfiddle.net/fdKKD/

总之,我创建一个简单的模型和一个简单的观点。当我设置模型上的属性,视图的console.log的渲染。

In short, I'm creating a simple model and a simple view. When I set a property on the model, the view console.log's "render".

我看到在Chrome 17和Safari,苹果相同的行为。

I'm seeing the same behavior in Chrome 17 and Safari, Mac.

这是我发疯。将AP preciate一些帮助。

This is driving me nuts. Would appreciate some help.

推荐答案

骨干需要加载任何的jQuery或的Zepto的的骨干,如果你打算,如果你使用一个视图做任何DOM操作(即)。您的HTML包含在这个顺序的东西:

Backbone requires either jQuery or Zepto to be loaded before Backbone if you intend to do any DOM manipulation (i.e. if you use a view). Your HTML includes things in this order:


  1. 下划线。

  2. 骨干。

  3. jQuery的。

所以,骨干不知道是否在加载时和你结束了正在使用的功能处于不确定的状态,应该使用jQuery或的Zepto。您原来的jsfiddle使用jQuery在侧边栏让jQuery将通过的jsfiddle的的你的&LT加载;脚本> 标签被击中,所以骨干看到了jQuery,使用它,一切正常。如果切换到无库(纯JS)

So Backbone doesn't know if it should use jQuery or Zepto when it loads and you end up with an undefined value being used a function. Your original jsfiddle uses jQuery in the sidebar so jQuery will be loaded by jsfiddle before your <script> tags are hit, so Backbone sees jQuery, uses it, and everything works. If you switch to "No-Library (pure JS)":

http://jsfiddle.net/ambiguous/pzgW7/

然后您将再次看到你的错误。如果包括jQuery的第一次:

then you'll see your error again. If you include jQuery first:

http://jsfiddle.net/ambiguous/C32Gd/

事情会工作。

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

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