我正在嘗試使用waypoints
和zepto
和RequireJS
。RequireJS + Zepto + Waypoints:無法讀取未定義的屬性'apply'
我requireJS配置是這樣的:
requirejs : {
options : {
baseUrl : '<%= config.app.js %>',
paths : {
almond : '../node_modules/almond/almond',
zepto : '../node_modules/zepto/zepto.min',
'progressbar' : '../node_modules/progressbar.js/dist/progressbar',
waypoints : '../node_modules/waypoints/lib/zepto.waypoints'
},
shim : {
zepto : {
exports : '$'
}
},
mainConfigFile: '<%= config.app.js %>/common.js',
include : ['common'],
name : 'almond',
out : 'dist/js/<%= pkg.name %>.js',
insertRequire: ['common'],
wrap: true
},
dist : {
options : {
optimize: 'uglify2'
}
},
dev : {
options : {
optimize: 'none'
}
}
},
此外,我common.js
文件如下:
define(['zepto', 'waypoints'], function($) {
var waypoint = $('#experience').waypoint({
handler: function(direction) {}
});
});
但加載頁面時,我得到以下錯誤:
Uncaught TypeError: Cannot read property 'apply' of undefined
錯誤,來自該行的waypoints
插件庫:
return this.$element[method].apply(this.$element, args)
當我調試代碼,我可以看到function ZeptoAdapter(element)
被調用兩次,一次用$('#experience')
作爲元素,一次用window
。第二次是失敗時,因爲this.$element
未定義。難道我做錯了什麼?包含zepto插件的正確方法是什麼?
謝謝,