my jquery plugin and accessing a global seems inappropriate. Better way?
<p>I asked a previous question and I feel I wasn't succinct enough. So , here is my code example and my accessing of a global. I feel this is bad form, but I can't find another way to do this given my plugin format.</p>

<p>I believe I could apply my functions to a method var and then instantiate that via the plugin in call, but so far - my plugin isn't set up like that and think that might be more work. But I'd like to hear from more experienced jQuery plugin creators.</p>

<p>Usage:
Data is front loaded. As dynamic content is created. I gobbled up some pertinent information pertaining to it, bundle it up, send an ajax call - then update the view. The thing is. My plugin could be called numerous times on a page. But the thing is I need to grab some data objects PRIOR to calling my plugin so I then can operate on them and determine "what I need to update". So that is my issue. I need to get some data outside of the plugin. THEN i need to pass it in. Is this considered "appropriate". </p>

<p>My hope was I could funnel the data into a method of the plugin and then when I call it I have the data to make some display choices.</p>

<pre><code>if ( typeof Object.create !== 'function' ) {
Object.create = function( obj ) {
    function F() {};
    F.prototype = obj;
    return new F();
};
}
// this is the global that I push each reiteration of data into.
var perLineDataArray = [];
(function( $, window, document, undefined ) {
var Sustainability = {
    _init: function( options, elem ) {
        var self = this;
        self.elem = elem;
        self.$elem = $( elem );
        /* plugin call has all the data I need, I pass it in here */
        self.perLineData = groupedperLineData;
        self.url = 'path_to_url/sustainability';
        self.options = $.extend( {}, $.fn.querysustainability.options, options );
        self._extractUrlData();
        self._cleanup();

    },
            _extractUrlData: function(){
               // this is where I would go thru each of the data objects and 
               // determine WHAT in the view needs updating based on some critera.
            },
    _getsustain: function()
            {
              var self = this;
              $.ajax({
                       // my ajax call data
                            success: function(data){
                                this._buildUpdate(data);
                            }
                  });
            },
    _buildDispaly: function( results ) {
        var self = this;
        self.sustainability = $.map( results, function( obj, i) {
            return $( self.options.wrapDisplay ).append ( obj.text )[0];
        });
    },
            _cleanup: function(){
               // clean out global array for next funneling of grouped up data
               perLineDataArray = [];
            },
    _showMessage: function() {
        var self = this;
        self.$elem[ self.options.transition ]( 500, function() {
             $(this).html( self.sustainability )[ self.options.transition ]( 500 );
        });

    },
};
$.fn.querysustainability = function( options, method ) {
    return this.each(function() {
        var sustainability = Object.create( sustainability );
        sustainability._init( options, this );
        $.data( this, 'querysustainability', sustainability );
    });
};

$.fn.querysustainability.options = {
    display: '&lt;span&gt;&lt;/span&gt;',
    usedClass : 'uniqueclass',
    transition: 'fadeToggle'
};


 })( jQuery, window, document );
</code></pre>

<p>I haven't worked out all the code yet, but that is the jist.. so here is how i would push the data into the global.</p>

<pre><code> //Some reiteration of building of HTML dom element displays.
 perLineDataArray.push(some_per_iteration_obj);
</code></pre>

<p>Then, when the display is build and I have all the objects I need - THEN I call the plugin.</p>

<pre><code>    jQuery('#planets').querysustainability({
        groupedperLineData: perLineDataArray
     });
</code></pre>

<p>Or I could add the global here:</p>

<pre><code>    $.fn.querysustainability.options = {
    display: '&lt;span&gt;&lt;/span&gt;',
    usedClass : 'uniqueclass',
    transition: 'fadeToggle',
    groupedperLineData: perLineDataArray
};
</code></pre>

<p>My gut is telling me I want the plugin to encapsulate everything but then another part of me feels I need to pass in what I need to operate on and now have my plugin retrieve it.</p>

<p>So, is there a way to call a sub-method of the plugin, store up the data set and then when I call the plugin, it has that data ready or ?</p>

<p>your thoughts? And if how do you feel I should solve this, code wise?</p>
