Bug Tracker

Modify

Ticket #9767 (closed feature: wontfix)

Opened 2 years ago

Last modified 2 years ago

It would be nice to have Ruby-like shortcuts for map()

Reported by: gurdiga@… Owned by:
Priority: low Milestone: 1.next
Component: core Version: 1.6.2
Keywords: Cc:
Blocking: Blocked by:

Description

It would be nice to have Ruby-like shortcuts for map(), so that one would be able to say:

$('table td.amount').map('innerHTML');

instead of

$('table td.amount').map(function() {
  return this.innerHTML;
});

or

$('#cardwall .tickets').map('getAttribute', 'data-hours');

instead of

$('#cardwall .tickets').map(function() {
  return this.getAttribute(data-hours);
});

or

$('.post .body').map('$excerpt', 100);

instead of

$('.post .body').map(function() {
  return $(this).excerpt(100);
});

Change History

comment:1 Changed 2 years ago by timmywil

  • Priority changed from undecided to low
  • Resolution set to wontfix
  • Status changed from new to closed
  • Component changed from unfiled to core

I see the advantage, but I don't think it belongs in jQuery. jQuery has its own style and consistency to its API and something like this would open up a new world of APIs that would only bloat the code.

comment:2 Changed 2 years ago by ajpiano

+1 to Timmy - It's nice, but a little too sugary for core.

comment:3 Changed 2 years ago by rwaldron

+1 to timmywill and ajpiano

You should definitely turn this into a "duck punch plugin", Paul Irish has written an excellent article on the subject:

 http://paulirish.com/2010/duck-punching-with-jquery/

Keep the jQuery team posted if the plugin gains traction and wide use

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.