Just a quick clarification on this. The this keyword within the "newMethod"
plugin you just made is already the jQuery object. All you need to do is
return this;

--
Brandon Aaron

On Wed, Dec 3, 2008 at 1:01 PM, 703designs <[EMAIL PROTECTED]> wrote:

>
> There's nothing special about chaining methods. You can do it in most
> decent languages (in PHP, you could design methods to allow something
> like: $toys->addNew("Block")->delete();) and all it involves is
> returning an instance of the current object. It's not a performance
> hit by any means.
>
> A chainable method, in jQuery, is written:
>
> $.fn.newMethod = function() {
>    // Function body...
>    return $(this);
> }
>
> As you can see, all that's happening is "this" is being converted to a
> jQuery object (defined by jQuery and its alias "$") and returned.
>
> Thomas
>
> On Dec 3, 1:54 pm, MorningZ <[EMAIL PROTECTED]> wrote:
> > "I can see it saving time as there is less
> > code to write; but on the flip side, I can see how it can becomes
> > harder to manage especially if there is an excess amount chaining
> > going on"
> >
> > That's your decision to make, and you can have the choice to do it one
> > way or the other
> >
> > One advantage to doing this
> >
> > $("#Results").html("Some Text").show();
> >
> > over this
> >
> > $("#Results").html("Some Text");
> > $("#Results").show();
> >
> > would be that the script doesn't have to retrieve that wrapped set a
> > second time
> >
> > On Dec 3, 12:55 pm, SLR <[EMAIL PROTECTED]> wrote:
> >
> > > I'm new to jQuery and I'm trying to learn some more about jQuery's
> > > chaining feature. Chaining methods seems to be one of jQuery's best
> > > features (at least this is how I see it described all over over the
> > > web).
> >
> > > From a developer standpoint, I can see it saving time as there is less
> > > code to write; but on the flip side, I can see how it can becomes
> > > harder to manage especially if there is an excess amount chaining
> > > going on.
> >
> > > Also, how does this affect performance? Does chaining use more, less,
> > > or the same amount of resources?
> >
> >
>

Reply via email to