I am writing a jQuery plugin and the plugin has secondary functions (see jQuery support). I would like to be able to loop through the elements that the jQuery object contains in order to do something to each of them. However, I cannot see how to access the original object since, in the scope of the secondary function, this obviously refers to the plugin object.
Is there any way to access the original elements or am I going to have to start thinking about alternative (jQuery UI -esque) techniques?
The code looks something like this:
(function ($) {
'use strict';
var
myNewPlugin,
mySecondaryFunction;
mySecondaryFunction = function () {
// the secondary function
// `this` refers to myNewPlugin
};
myNewPlugin = (function () {
var closedPrivateVariables;
return function () {
// the function called from the jQuery object
return this;
};
}());
myNewPlugin.mySecondaryFunction;
$.fn.myNewPlugin = myNewPlugin;
}(jQuery));
Not duplicates (questions which sound similar but are not the same)