Iterator.js 473 B

123456789101112131415161718192021
  1. function Iterator(items) {
  2. this.items = items || [];
  3. }
  4. Iterator.prototype.iterate = function(callback) {
  5. this.items.forEach(callback);
  6. };
  7. /* Calls a method on every item passing the arguments through */
  8. Iterator.prototype.proxyCall = function(methodName) {
  9. var args = Array.prototype.slice.call(arguments, 1);
  10. var results = [];
  11. this.iterate(function(item) {
  12. results.push(item[methodName].apply(item, args));
  13. });
  14. return results;
  15. };