Bug Tracker

Modify

Ticket #9800 (closed enhancement: fixed)

Opened 3 years ago

Last modified 23 months ago

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 3 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

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

comment:2 Changed 2 years ago by dmethvin

  • Milestone changed from None to 1.8

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

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

Noticed this was unowned for 1.8

comment:6 Changed 2 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 2 years ago by rwaldron

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

comment:8 Changed 2 years 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:9 Changed 2 years ago by dmethvin

@cowboy can you submit a pull request?

comment:10 Changed 23 months ago by timmywil

  • Status changed from reopened to open

comment:11 Changed 23 months ago by cowboy

comment:12 Changed 23 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.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.