定义的模块返回不出去呢
Uncaught TypeError: Cannot read property 'ScrollTo' of undefined
Uncaught TypeError: Cannot read property 'ScrollTo' of undefined
2016-05-11
你看你的数组的右括号在哪里呢?你的function不能写在[]里面的。
define(['jquery'],function ($) { function ScrollTo(opts) { this.opts = $.extend({},ScrollTo.DEFAULTS,opts); this.$el = $('html,body'); } ScrollTo.prototype.move = function () { var opts = this.opts; this.$el.animate({ scrollTop:opts.dest },opts.speed); }; ScrollTo.prototype.go = function () { this.$el.scrollTop(this.opts.dest); }; ScrollTo.DEFAULTS = { dest:0, speed:500 }; return { ScrollTo:ScrollTo }; });
看到区别了吗?
define(['jquery',function($){
function ScrollTo(opts){
this.opts = $.extend({},ScrollTo.Defaults,opts);
this.$el = $('html,body');
};
ScrollTo.prototype.move = function(){
var opts = this.opts
this.$el.animate({scrollTop:opts.dest},opts.speed);
};
ScrollTo.prototype.go = function(){
this.$el.scrollTop(this.opts.dest);
};
ScrollTo.Defaults = {
dest:0,
speed:800
};
return {
ScrollTo : ScrollTo
};
}])
举报