0

我正在研究一个使用 JScroll 的 js 文件。事件的回调jsp-scroll-y在以下函数中定义

 function initWall() {
     //callback from jqueryscrollpane
     Scroll_TimeLine_Instance = function (event, scrollPositionY, isAtTop, isAtBottom){     
         //get more content
         if (isAtBottom) {
             GetMoreDate(objid, vwrsid, secid, orgid, incflwr, qty, mintlid, maxtlid, successGetTimeLineCallback, failureGetTimeLineCallback);
         }
     }();
}

定义了另一个函数,然后将此回调绑定到 jsScroll

function reapplyScroll() {
     Utilities.DestroyScrollBar($(_target).closest('.widgetBody'));
     Utilities.ApplyScrollBar($(_target).closest('.widgetBody'), false, Scroll_TimeLine_Instance);
            }

Utilities.ApplyScrollBar = function (element, showScrollBar, scrollCallback) {
    $(element).jScrollPane({
        horizontalGutter: 5,
        verticalGutter: 5,
        'showArrows': false
    }).bind('jsp-scroll-y', scrollCallback);

    if (!showScrollBar) {
        $(element).find('.jspDrag').hide();
    }
}

回调从未被调用,我发现这是因为它未定义。如果我删除Immediate object initialization(); 从创建功能后,一切正常。

谁能解释一下?我不明白为什么它被立即调用,所以我认为这是创建它的人的错误,我不知道为什么它会导致这个变量未定义?

4

1 回答 1

0

这是undefined因为函数(即被立即调用)没有return任何价值

所以看起来这确实是图书馆的一个错误..


要么在最后删除();,或者如果你想在那里调用它,只需在以下行中调用它

function initWall() {
     //callback from jqueryscrollpane
     Scroll_TimeLine_Instance = function (event, scrollPositionY, isAtTop, isAtBottom){     
         //get more content
         if (isAtBottom) {
             GetMoreDate(objid, vwrsid, secid, orgid, incflwr, qty, mintlid, maxtlid, successGetTimeLineCallback, failureGetTimeLineCallback);
         }
     }; /// this is assigning the function to our variable
     Scroll_TimeLine_Instance (); // this is the invokation
}
于 2013-10-11T13:53:20.970 回答