Skip to content

Instantly share code, notes, and snippets.

@sebmarkbage
Created January 21, 2010 18:47
Show Gist options
  • Save sebmarkbage/283056 to your computer and use it in GitHub Desktop.
Save sebmarkbage/283056 to your computer and use it in GitHub Desktop.
var dontEnum = ['toString', 'toLocaleString', 'valueOf', 'toSource', 'watch', 'unwatch', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable'];
var failsEnumTest = (function(){
for (var k in { toString: {} }) return false;
return true;
})();
Object.each = function(obj, fn){
for (var key in obj) fn(obj[key], key);
if (failsEnumTest)
for (var i=0,l=dontEnum.length;i<l;i++){
var key = dontEnum[i], value = obj[key];
if (value !== Object.prototype[key]) fn(value, key);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment