在使用seajs时遇到一个奇怪的问题,使用seajs.use和require,在使用jquery时发现。
问题是这样的,使用 jquery 是 1.8.3 版本,使用
seajs.use('../../1.8.3/jquery.js',function($){
console.log($); // null,始终返回 null, 不能使用
});
直接定义模块
define(function(require,exports,module){
require('../../1.8.3/jquery.js');
console.log($); // ok,返回 jquery 函数
});
通过配置文件
seajs.config({
base : 'lib',
alias:{
jquery : '1.8.3/jquery'
}
});
seajs.use('jquery',function($){
console.log($); // 能够获取
});
通过上面的对比,并没有发现有什么问题,是use和require的区别吗?为什么会有这样的情况呢。为什么在使用use的时候需要将 jquery 模块 返回 $.noConflict()。