Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 事件侦听器?_Javascript_Jquery - Fatal编程技术网

Javascript 事件侦听器?

Javascript 事件侦听器?,javascript,jquery,Javascript,Jquery,我有一个无限卷轴类: (function(){ "use strict"; var InfiniteScroll = function() { this.init(); }; var p = InfiniteScroll.prototype = mc.BaseClass.extend(gd.BaseClass); p.BaseClass_init = p.init; /* * Public properties */ p.loading = false; /* * Pub

我有一个无限卷轴类:

(function(){
"use strict";

var InfiniteScroll = function() {
    this.init();
};

var p = InfiniteScroll.prototype = mc.BaseClass.extend(gd.BaseClass);
p.BaseClass_init = p.init;

/*
 * Public properties
 */
p.loading = false;

/* 
 * Public methods
 */
p.init = function() {
    // Super
    this.BaseClass_init();

    // Init
    this.ready();

};

p.ready = function() {

    this._initInfiniteScroll();

};

p._initInfiniteScroll = function() {

    $(window).scroll(function(){  
        if($(window).scrollTop() == $(document).height() - $(window).height()){

            if(!p.loading)
            {
                p.loading = true;
                //send a message up to say loading
            }

        }  
    });   

}


mc.InfiniteScroll = InfiniteScroll;
}(window));
现在,这是从另一个类调用的:

this.infiniteScroll = new mc.InfiniteScroll();
在另一个类中,我希望在我有评论的地方触发滚动时听到: //向上发送消息说正在加载


我只是想知道如何才能做到这一点,我对AS3中的事件侦听器很熟悉,但有人能为我指出js的正确方向吗?

您可以在类中实现自定义事件处理程序,并在其他类(如中)中添加侦听器函数

您将在_initInfiniteScroll函数中使用它,如:

//send a message up to say loading
this.fire({ type: "ContentLoadingEvent" });

不过,正如帖子中所建议的,为你的InfiniteScroll事件创建一个单独的类更好。

我的观点是@Fletcher91所说的