Bug Tracker

Opened 12 years ago

Closed 11 years ago

#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:
Blocked by: Blocking:

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 (12)

comment:1 Changed 12 years ago by addyosmani

Component: unfiledtraversing
Priority: undecidedlow
Status: newopen
Type: bugenhancement

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

comment:2 Changed 11 years ago by dmethvin

Milestone: None1.8

comment:3 Changed 11 years 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 11 years ago by gibson042

I've thought a bit more about this, and would like to propose .addBack instead of .addPrior: #11128

comment:5 Changed 11 years ago by Rick Waldron

Owner: set to Rick Waldron
Status: openassigned

Noticed this was unowned for 1.8

comment:6 Changed 11 years ago by dmethvin

Owner: changed from Rick Waldron to dmethvin
Summary: New method: .addPrior (supersedes .andSelf)New method: .addBack (supersedes .andSelf)

PR for discussion as .addBack().

https://github.com/jquery/jquery/pull/777

comment:7 Changed 11 years ago by Rick Waldron

Resolution: fixed
Status: assignedclosed

comment:8 Changed 11 years ago by cowboy

Resolution: fixed
Status: closedreopened

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:9 Changed 11 years ago by dmethvin

@cowboy can you submit a pull request?

comment:10 Changed 11 years ago by Timmy Willison

Status: reopenedopen

comment:12 Changed 11 years ago by Ben Alman

Resolution: fixed
Status: openclosed

jQuery#addBack supports an optional selector that can be used to filter the prior set before adding it back. Fixes #9800

Changeset: 02dd7c570bf4dbbdfc168f4352d04c667447be5d

Note: See TracTickets for help on using tickets.