$不是函数。骨干,jQuery和Browserify [英] $ is not a function. Backbone, jQuery and Browserify
本文介绍了$不是函数。骨干,jQuery和Browserify的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建节点的应用程序与browserify模块化前端code。
不幸的是,我不能让骨干的工作,因为它是抛出这个错误:
I am creating node app with browserify to modularize frontend code. Unfortunately, I can't get Backbone working, because it's throw this error:
Uncaught TypeError: Property '$' of object #<Object> is not a function
jQuery是此脚本之前加载:
jQuery is loaded before this script:
var _ = require('underscore'),
Backbone = require('backbone');
// Here, jQuery works fine.
$(function() {
Backbone.history.start();
});
这似乎是骨干使用browserify时找不到jQuery的。
It's seem like Backbone couldn't find jQuery when using browserify.
推荐答案
只要设置骨干。$ =窗口$
手动。骨干网会在一个全局变量的jQuery(这是通过捕捉定义这个
),并很可能browserify在全球范围内(这与CommonJS的一致)运行脚本没有。
Just set Backbone.$ = window.$
manually. Backbone looks for jquery in a global variable (which is defined by capturing this
) and it's likely that browserify runs script not in a global context (which is consistent with CommonJS).
这篇关于$不是函数。骨干,jQuery和Browserify的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文