object.forEach [JS 1.8]


/ Published in: JavaScript
Save to your folder(s)

object.forEach
=========
*Requires JavaScript 1.8*

`void object.forEach(function callback(item, value)[, thisObject])`


Copy this code and paste it in your HTML
  1. Object.prototype.forEach = function(fun /*, thisp*/) {
  2. // if this gets called on an array, use appropriate forEach
  3. if ( Object.prototype.toString.call(this) == "[object Array]" ) return Array.prototype.forEach.apply(this, Array.prototype.slice.call(arguments));
  4. if ( typeof fun != "function" ) throw new TypeError();
  5. let it = Iterator(this), thisp = arguments[1];
  6. try {
  7. while (true) {
  8. fun.apply(thisp, it.next());
  9. }
  10. } catch (err if err instanceof StopIteration) {}
  11. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.