Another "solution" i found on a Blog.
Instead of adding a function to the Plugin, create a seperate object
within the scope of the plugin.

;(function($)
{
    $.fn.pluginname = function(options)
    {
        // private method
        function _doSomethingPrivate()
        {
                ....
        }

        // public method
        $.fn.pluginname_doSomethingPublic = function()
        {
            _doSomethingPrivate();
            return this;
        }

    };

Like that you still could write something like

$
('#example').pluginname().pluginname_doSomethingPublic().otherJquery();

Of course there are still some limits to it. ie not declared before $
().pluginname().
So from this point of view the way jmap is handling it is indeed
somehow better.
Its just, i like the way of having seperate methods instead of having
one multipurpose method.
But i guess i will go the way jmap does it, i still can seperate the
"comands" into private methods.
Its just u can't realy seperate anymore into private or plubic
methods.



On 3 Sep., 16:30, Balazs Endresz <[EMAIL PROTECTED]> wrote:
> It depends on what the public method returns. If it returns the jQuery
> object (the 'this' inside the plugin) then you have to call $
> ('#example').pluginname.doSomethingPublic().pluginname.doSomethingElse().
>
> If you want to chain your methods directly you have to return 'this'
> inside your public methods, which refers to $.fn.pluginname (not to
> the jquery object!).
> But doing this will prevent you from chaining jquery methods (most of
> the plugins are chainable). If you don't like this and would like to
> get the jquery object back, you can do that with another public
> method:
> $.fn.pluginname.returnJQuery = function(){  return _jquery;  }
> where _jquery is defined where your _options object: var _jquery=this;
> so $().pluginname.doSomethingPublic().doSomethingElse().returnJQuery()
> will return the original jQuery object.
>
> The only problem(?) with both is that it's a bit different from how
> jQuery is generally used. That's why, I think, the jMaps approach is
> somewhat better.
>

Reply via email to