I ran into the same question when I developed my first plug-in
recently.  I don't know if it's best practice, but what I found was
that when you're returning a value that is not part of the chain, the
method you chose worked best.

Also try this:

jQuery.myObj = function(params) {
      var private = funciton(params) {
            alert(params);
      }

      return {
           public: somePrivateMethod('Hello World')
      };
}

This allows you to create public and private methods and properties
within your JQuery code.  The private method can only be called by the
public method.  But the public method can be called by any instance of
the JQuery object.

Make sense?

Jocko

sgrover wrote:
> I'm working on a jQuery plugin, which is primarily a series of utility
> functions.  I need to worry about namespace problems, so I have opted
> for the option to add an object to the base jQuery object.
>
> i.e.
>
> jQuery.myObj = { . . .  };
>
> What I'm not clear on is if this is the best approach.  Thus far
> everything is working fine, but that jQuery.fn.myObj approach and the
> jQuery.fn.extend() method are a little over my head (so far).  Are these
> better approaches to be using?
>
> The methods I'm creating return various values - ints, dates, etc.  So I
> don't think the jQuery.fn.myObj approach would work here - it would
> break chaining.
>
> So, I'm looking for any guidance you may be able to offer.  I'm the type
> that will plow through this anyways and make a choice where need be, but
> a second opinion is ALWAYS appreciated.. Just in case I'm doing things
> wrong... :)  Thanks in advance.
>
> Shawn

Reply via email to