jQuery源码分析之Callbacks详解

2020-05-23 06:21:26易采站长站整理

                if (list && (!fired || stack)) {
                    //修正参数
                    //在这里,context索引为0
                    //而参数列表索引为2
                    //转换为数组访问是因为对象表示更加的消耗资源,在顶层的fire()代码中有auto[记忆参数,自动执行]这个功能,如果采用对象则开销了更大的内存
                    args = [context,
                        args ?
                        args.slice && args.slice()
                        || toSlice.call(args) :
                        []                    ];
                    fire(args);
                }
                return this;
            },
            remove: function () {//移除一个回调函数
                if (list) {
                    each(arguments, function (item) {
                        var index;
                        //可能有多项,index可以在循环中表示检索的范围,之前检索的过的可以不用再检索
                        while ((index = inArray(item, list, index)) > -1) {