2015-02-08 36 views
1

我正在嘗試使用waypointszeptoRequireJSRequireJS + 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插件的正確方法是什麼?

謝謝,

回答

0

Waypoints對於CommonJS或AMD的導出沒有做任何事情。我相信你需要墊片一樣好:

shim : { 
    zepto : { 
    exports : '$' 
    }, 
    waypoints: { 
    deps: ['zepto'], 
    exports: 'Waypoint' 
    } 
} 
-1

這解決我的問題

shim : { 
    jqueryWaypoints:{ 
     deps: ['jquery'], 
     exports: 'jqueryWaypoints' 
    } 
} 
相關問題