我有一个无限的滚动类:
p.infiniteScrollFnc = undefined;
p.init = function() {
this.infiniteScrollFnc = this.infiniteScroll.bind(this);
};
p.initInfiniteScroll = function(cb){
$(window).on('scroll', this.infiniteScrollFnc.bind(cb));
};
p.terminateInfiniteScroll = function(){
$(window).off('scroll', this.infiniteScrollFnc);
};
p.infiniteScroll = function(cb){
if($(window).scrollTop() == $(document).height() - $(window).height()){
console.log('load more');
this.terminateInfiniteScroll();
cb();
}
};
我希望通过以下方式发送回调:
this.infiniteScroll.initInfiniteScroll(this.myCallback);
但我收到错误:
Uncaught TypeError: cb is not a function
答案 0 :(得分:0)
如果你想使用bind传递cb
,那么你把它作为第二个参数,因为第一个是上下文:
p.initInfiniteScroll = function (cb) {
$(window).on('scroll', this.infiniteScrollFnc.bind(this, cb));
};