Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can't access the settings in the <code>compSlider</code> function because in your example they are defined in <code>init()</code>, making them local to that function. If you moved the declaration up in scope:</p> <pre><code>$.fn.compSlider = function( method, options ) { var settings = $.extend( {}, defaults, options ); }; </code></pre> <p>Then you'd be able to access it there. Or just defining it (<code>var settings;</code>) in compSlider and removing <code>var</code> in <code>init()</code> would be enough.</p> <p>Update:</p> <p>In repsonse to your comment, yes, sorry, forgot about the issue #2. As it is, you will not be able to access the settings for each plugin object because you cannot "go down" in scope. In other words, you cannot access a local variable of a function from outside of that function. And that is what settings are, local to the <code>compSlider</code> function (if you use the structure I proposed), they are lower in scope as far as your <code>opt()</code> function is concerned.</p> <p>You can, of course, always go up in scope. To achieve this you could set up a variable in the plugin's global space that stores references to all objects created.</p> <pre><code>var compSliderObjects = []; $.fn.compSlider = function( method, options ) { //store objects in compSliderObjects }; </code></pre> <p>However, this is just the an idea, and you still need to figure out how you want to access the compSliderObjects and pull the right settings. Will each object have a unique id? If so, an array of objects (<code>{id: 2, settings: data}</code>). If not, you need to figure out how you want to uniquely identify them and pull them from the array. </p> <p>Also, do you really need to access them globally? It's less work and code to just call the object and get the settings (as shown in the fiddle).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload