Bug Tracker

Opened 5 years ago

Closed 5 years ago

#15158 closed feature (migrated)

Allow to fire callbacks in reversed order using $.Callbacks object

Reported by: logo Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.11.1
Keywords: Cc:
Blocked by: Blocking:

Description

A new flag (e.g. "reversed") could be added to $.Callbacks object, which would make callbacks.fire() method to fire callbacks in reversed order.

Stack-based execution patterns are very popular and this flag would add another possible usage to this simple yet powerful tool.

Example:

function fn1( value ) {
  console.log( value );
}
function fn2( value ) {
  console.log( "fn2 says: " + value );
  return false;
}

var callbacks = $.Callbacks( "reversed" );
callbacks.add( fn1 );
// Outputs: foo!
callbacks.fire( "foo!" );
callbacks.add( fn2 );
// Outputs: fn2 says: bar!, foo!
callbacks.fire( "bar!" );

Change History (2)

comment:1 Changed 5 years ago by dmethvin

If this had a low (near zero) byte cost it could be possible to add, but someone would need to do an implementation to see the cost. The number of people using $.Callbacks directly seems to be very low so this would probably not benefit many people.

comment:2 Changed 5 years ago by m_gol

Resolution: migrated
Status: newclosed
Note: See TracTickets for help on using tickets.