Bnaya

JS/Q/1

Jan 9th, 2012
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. my = {
  2.     each: function(collection, callback) {
  3.             if(collection instanceof Array) {
  4.                 for(i = 0; i < collection.length; i++) {
  5.                     callback.call(collection[i], i, collection[i]);
  6.                 }
  7.             } else {
  8.                 for(propi in collection) {
  9.                     if(collection.hasOwnProperty(propi)) {
  10.                         callback.call(collection[propi], propi, collection[propi]) ;
  11.                     }
  12.                 }
  13.                
  14.             }
  15.  
  16.             return collection;
  17.         }
  18. };
  19.  
  20. Object.prototype.each = function(callback){
  21.     return my.each(this, callback);
  22. };
Advertisement
Add Comment
Please, Sign In to add comment