0

I am troubleshooting a slider problem at the moment, however, I don't know javascript that well, I have isolated the .js file that is responsible for the slider functioning, there is a destroy function that I would like to fire off, the code looks like this

(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;
    }
}

How would I fire off the destroy function in this scenario?

1
  • It would have to be accessed from within PeBackgroundSlider(), due it's private scope in that function. Commented Jun 4, 2017 at 19:09

1 Answer 1

2

You can't as it is right now.

To call it you must "export" it as follows:

function PeBackgroundSlider(target, conf) {

...

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

  return { "destroy": destroy };
}

From the caller:

var ret = PeBackgroundSlider();

Now you can do:

ret.destroy();

Or, more concise:

  return destroy;

And:

innerDestroy = PeBackgroundSlider();

And finally:

innerDestroy();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.