开发者

jQuery pushStack

开发者 https://www.devze.com 2023-01-29 11:10 出处:网络
I need some help to understand pushStack Here I\'ve made 开发者_StackOverflow社区an example where the results using it or not are the same http://jsfiddle.net/Bz5n9/2/ so I think i really didn\'t get

I need some help to understand pushStack

Here I've made 开发者_StackOverflow社区an example where the results using it or not are the same http://jsfiddle.net/Bz5n9/2/ so I think i really didn't get what is it for.

Thanks!


You're currently adding to the collection, pushing a new collection on the stack that's already the result (you could just return the result of this.add()). What this does is instead of pushing .b elements on the stack as a new element, it pushes a new set with .b elements and the #2 <li> you started with.

Instead, you instead should pass the elements directly (no .add() call), like this:

return this.pushStack(newCollection, "agregate", "");

You can test it out here.


Ben does a good job of explaining it here:

http://www.bennadel.com/blog/1739-Using-PushStack-In-jQuery-Plugins-To-Create- New-Collections.htm

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号