Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Implemented an object.forEach. I benchmarked this and it's actually f…

…aster than a plain for..in loop over an object.
  • Loading branch information...
commit 47a3aeb915817c2407444623cdc6dddc2aeae9e1 1 parent 8cc2ab4
@creationix authored
Showing with 17 additions and 0 deletions.
  1. +17 −0 lib/proto.js
View
17 lib/proto.js
@@ -0,0 +1,17 @@
+var proto = Object.prototype;
+
+// Implements a forEach much like the one for Array.prototype.forEach, but for
+// and object.
+if (typeof proto.forEach !== 'function') {
+ Object.defineProperty(proto, "forEach", {enumarable: false, value: function (callback, thisObject) {
+ var keys = Object.keys(this);
+ var length = keys.length;
+ sys.p(keys);
+ for (var i = 0; i < length; i++){
+ key = keys[i];
+ callback.call(thisObject, this[key], key, this);
+ }
+ }});
+}
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.