Advertisement
stuppid_bot

foreach js

Sep 5th, 2014
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // o.hasOwnProperty можно переопределить
  2. function hasOwn(o, p) {
  3.     return Object.prototype.hasOwnProperty.call(o, p);
  4. }
  5.  
  6. // each(obj, function (value, index, obj) {}[, thisArg=obj])
  7. function each(o, cb, s) {
  8.     var i;
  9.     s = s || o;
  10.     if (typeof o.length != 'undefined') {
  11.         for (i = 0; i < o.length; ++i) {
  12.             if (cb.call(s, o[i], i, o) === false) {
  13.                 break;
  14.             }
  15.         }
  16.     } else {
  17.         for (i in o) {
  18.             if (hasOwn(o, i)) {
  19.                 if (cb.call(s, o[i], i, o) === false) {
  20.                     break;
  21.                 }
  22.             }
  23.         }
  24.     }
  25.     return o;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement