Bug Tracker

Opened 5 years ago

Closed 4 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 5 years ago by addyosmani

  • Component changed from unfiled to traversing
  • Priority changed from undecided to low
  • Status changed from new to open
  • Type changed from bug to enhancement

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

comment:2 Changed 5 years ago by dmethvin

  • Milestone changed from None to 1.8

comment:3 Changed 5 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 5 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 5 years ago by rwaldron

  • Owner set to rwaldron
  • Status changed from open to assigned

Noticed this was unowned for 1.8

comment:6 Changed 4 years 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().

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

comment:7 Changed 4 years ago by rwaldron

  • Resolution set to fixed
  • Status changed from assigned to closed

comment:8 Changed 4 years ago by cowboy

  • Resolution fixed deleted
  • Status changed from closed to reopened

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 4 years ago by dmethvin

@cowboy can you submit a pull request?

comment:10 Changed 4 years ago by timmywil

  • Status changed from reopened to open

comment:12 Changed 4 years ago by Ben Alman

  • Resolution set to fixed
  • Status changed from open to closed

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.