/**
 * util-events.js - The minimal events support
 */

var eventsCache = {}

// Bind event
seajs.on = function(event, callback) {
  if (!callback) return seajs

  var list = eventsCache[event] || (eventsCache[event] = [])
  list.push(callback)

  return seajs
}

// Remove event. If `callback` is undefined, remove all callbacks for the
// event. If `event` and `callback` are both undefined, remove all callbacks
// for all events
seajs.off = function(event, callback) {
  // Remove *all* events
  if (!(event || callback)) {
    eventsCache = {}
    return seajs
  }

  var list = eventsCache[event]
  if (list) {
    if (callback) {
      for (var i = list.length - 1; i >= 0; i--) {
        if (list[i] === callback) {
          list.splice(i, 1)
        }
      }
    }
    else {
      delete eventsCache[event]
    }
  }

  return seajs
}

// Emit event, firing all bound callbacks. Callbacks are passed the same
// arguments as `emit` is, apart from the event name
var emit = seajs.emit = function(event) {
  var list = eventsCache[event]
  if (!list) return seajs

  var args = []

  // Fill up `args` with the callback arguments.  Since we're only copying
  // the tail of `arguments`, a loop is much faster than Array#slice
  for (var i = 1, len = arguments.length; i < len; i++) {
    args[i - 1] = arguments[i]
  }

  // Copy callback lists to prevent modification
  list = list.slice()

  // Execute event callbacks
  for (i = 0, len = list.length; i < len; i++) {
    list[i].apply(global, args)
  }

  return seajs
}

// Emit event and return the specified property of the data
function emitData(event, data, prop) {
  emit(event, data)
  return data[prop]
}



@@ -1005,16 +1005,22 @@
 on(event
+, data
 ) %7B%0A  va
@@ -1050,291 +1050,30 @@
 ent%5D
-%0A  if (!list) return seajs%0A%0A  var args = %5B%5D%0A%0A  // Fill up %60args%60 with the callback arguments.  Since we're only copying%0A  // the tail of %60arguments%60, a loop is much faster than Array#slice%0A  for (var i = 1, len = arguments.length; i %3C len; i++) %7B%0A    args%5Bi - 1%5D = arguments%5Bi%5D%0A  %7D%0A%0A
+, fn%0A%0A  if (list) %7B%0A  
   //
@@ -1117,16 +1117,18 @@
 ication%0A
+  
   list =
@@ -1142,16 +1142,18 @@
 lice()%0A%0A
+  
   // Exe
@@ -1179,86 +1179,60 @@
 s%0A  
-for (i = 0, len = list.length; i %3C len; i++) %7B%0A    list%5Bi%5D.apply(global, args)
+  while ((fn = list.shift())) %7B%0A      fn(data)%0A    %7D
 %0A  %7D

Simplify code for seajs.emit