On Mar 3, 9:25 am, Leanan <[EMAIL PROTECTED]> wrote: > Hmmm, ok. > > So with that setup, I (as a user) could do > $.myAwesomePlugin.startRockin? I notice you have the options stuff > under simply $.fn.myAwesomePlugin. So what if I wanted to call > startRockin and set defaults, too? Does > $.myAwesomePlugin.startRockin(options_go_here) do it? Or do I have to > do $.myAwesomePlugin(options_here), then > $.myAwesomePlugin.startRockin?
In the Learning jQuery article, there's an example in the section titled "Provide public access to secondary functions as applicable." What gets passed to your secondary/utility functions is completely dependent on what the functions need. If they need access to the options, pass the options, if they don't, then don't. Also, note that Mike's examples use $.fn.plugin.secondary, while my example uses $.plugin.secondary. This comes down to personal preference, so choose whichever you like better. It will be unlikely for a user to call a secondary function out of context if it requires information about the options, so the scenario you're asking about is unusual. If you have a specific example in mind, feel free to explain it. Also, note that you wouldn't do: $.myAwesomePlugin(options_here) as you've written above, but rather: $(selector).myAwesomePlugin(options_here) > I've been reading these two articles over and over, and I've kind of > got it (I think) but one or two things I still don't quite grasp. The > articles are: > > http://docs.jquery.com/Plugins/Authoring > http://www.learningjquery.com/2007/10/a-plugin-development-pattern > > I rather like the second article, it seems failry straightforward. My > only complaint is that it doesn't show any example calls at the end > when all the code is put together. And that is where I keep getting > hung up. The only thing not shown at the end of the article is how you would call one of the secondary functions from outside of the plugin. This is because it's pretty uncommon. For one use case, check out http://docs.jquery.com/Types#Proxy_Pattern > For my example: > > I have my plugin that looks more or less like what I have in my intial > post. When I try to call $.myAwesomePlugin.startRockin, firebug tells > me that $.myAwesomePlugin.startRockin has no properties. From reading > the second article, it looks like maybe I want to do > $.fn.myAwesomePlugin.startRockin. Which is great, but I have a few > different functions that use the same defaults/options, and I really > don't want to reproduce the options = $.extend code. > > If someone could kindly tell me what I'm missing or getting mixed up > I'd greatly appreciate it. I know I'm close. Again, this all comes down to what your specific functions are doing. Are you actually trying to create multiple methods (methods = $().x(); functions = $.x();) or multiple functions that one method uses?