Posted By

Sephr on 02/23/09


Tagged

object prototype foreach


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

enajenkins
kesla


object.forEach


 / Published in: JavaScript
 

object.forEach

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

  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. var thisp = arguments[1];
  6. for ( i in this ) {
  7. if ( this.hasOwnProperty(i) ) fun.call(thisp, i, this[i]);
  8. }
  9. }

Report this snippet  

You need to login to post a comment.