Ticket #9800 (closed enhancement: fixed)
New method: .addBack (supersedes .andSelf)
| Reported by: | cowboy | Owned by: | dmethvin |
|---|---|---|---|
| Priority: | low | Milestone: | 1.8 |
| Component: | traversing | Version: | 1.6.2 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
Ok. .andSelf is somewhat confusingly named. What is "self" anyways? Let's come up with a better name for this method, and in the process, add a signature by which the previous-set-of-elements-to-be-added may be filtered. How about .addPrior? It's like .add but it specifically adds elements from the prior set.
Here's a version, as a plugin, with some usage examples: https://gist.github.com/1076570
Note: .andSelf should just be aliased to this new method, and documented as deprecated. We wouldn't need to change the docs for .andSelf, since it would still behave normally.
Change History
comment:1 Changed 2 years ago by addyosmani
- Priority changed from undecided to low
- Status changed from new to open
- Component changed from unfiled to traversing
- Type changed from bug to enhancement
comment:3 Changed 18 months ago by gibson042
I like that this enhances the chain-stack analogy where filters/traversals/etc. push, .end() pops, and .prevObject peeks.
comment:4 Changed 18 months ago by gibson042
I've thought a bit more about this, and would like to propose .addBack instead of .addPrior: #11128
comment:5 Changed 16 months ago by rwaldron
- Owner set to rwaldron
- Status changed from open to assigned
Noticed this was unowned for 1.8
comment:6 Changed 13 months ago by dmethvin
- Owner changed from rwaldron to dmethvin
- Summary changed from New method: .addPrior (supersedes .andSelf) to New method: .addBack (supersedes .andSelf)
PR for discussion as .addBack().
comment:7 Changed 13 months ago by rwaldron
- Status changed from assigned to closed
- Resolution set to fixed
comment:8 Changed 13 months ago by cowboy
- Status changed from closed to reopened
- Resolution fixed deleted
I'm re-opening this, because the second half of the ticket, "...in the process, add a signature by which the previous-set-of-elements-to-be-added may be filtered..." wasn't addressed, and I'd hate to see it get lost because it's so useful.
See https://gist.github.com/1076570 "find+filter" example for reference.
comment:11 Changed 13 months ago by cowboy
@dmethvin done. https://github.com/jquery/jquery/pull/803
comment:12 Changed 13 months ago by Ben Alman
- Status changed from open to closed
- Resolution set to fixed
jQuery#addBack supports an optional selector that can be used to filter the prior set before adding it back. Fixes #9800
Changeset: 02dd7c570bf4dbbdfc168f4352d04c667447be5d
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Marking as valid, switching to enhancement and opening for discussion.