如何执行嵌套的Javascript函数

时间:2017-06-04 19:08:22

标签: javascript jquery

我正在对滑块问题进行故障排除,但是,我不知道javascript那么好,我已经隔离了负责滑块功能的.js文件,还有一个我要解雇的destroy函数关闭,代码看起来像这样

(function ($) {

$.pixelentity = $.pixelentity || {version: '1.0.0'};

$.pixelentity.peBackgroundSlider = {    
    conf: {
        api: false,
        wait: false
    },
    paused: false
};

function PeBackgroundSlider(target, conf) {

    ...

    function destroy() {
        prevColor = currentColor = currentBW = jwindow = jthis = undefined;
        target.data("peBackgroundSlider", null);
        target = undefined;
    }
}

如何在这种情况下解除销毁功能?

1 个答案:

答案 0 :(得分:2)

你现在不能。

要调用它,您必须按如下方式“导出”它:

function PeBackgroundSlider(target, conf) {

...

function destroy() {
    prevColor = currentColor = currentBW = jwindow = jthis = undefined;
    target.data("peBackgroundSlider", null);
    target = undefined;
  }

  return { "destroy": destroy };
}

来自来电者:

var ret = PeBackgroundSlider();

现在你可以做到:

ret.destroy();

或者,更简洁:

  return destroy;

innerDestroy = PeBackgroundSlider();

最后:

innerDestroy();