/ Published in: JavaScript
object.forEach
=========
*Requires JavaScript 1.8*
`void object.forEach(function callback(item, value)[, thisObject])`
=========
*Requires JavaScript 1.8*
`void object.forEach(function callback(item, value)[, thisObject])`
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
Object.prototype.forEach = function(fun /*, thisp*/) { // if this gets called on an array, use appropriate forEach if ( Object.prototype.toString.call(this) == "[object Array]" ) return Array.prototype.forEach.apply(this, Array.prototype.slice.call(arguments)); if ( typeof fun != "function" ) throw new TypeError(); let it = Iterator(this), thisp = arguments[1]; try { while (true) { fun.apply(thisp, it.next()); } } catch (err if err instanceof StopIteration) {} }