Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- my = {
- each: function(collection, callback) {
- if(collection instanceof Array) {
- for(i = 0; i < collection.length; i++) {
- callback.call(collection[i], i, collection[i]);
- }
- } else {
- for(propi in collection) {
- if(collection.hasOwnProperty(propi)) {
- callback.call(collection[propi], propi, collection[propi]) ;
- }
- }
- }
- return collection;
- }
- };
- Object.prototype.each = function(callback){
- return my.each(this, callback);
- };
Advertisement
Add Comment
Please, Sign In to add comment