Skip to content

Instantly share code, notes, and snippets.

@anddoutoi
Created January 23, 2012 21:59
Show Gist options
  • Save anddoutoi/1665751 to your computer and use it in GitHub Desktop.
Save anddoutoi/1665751 to your computer and use it in GitHub Desktop.
JavaScript utility functions
var forEachInObject = (function () {
'use strict';
var fn = function ( f, args ) {
var o = this,
keys = Object.keys( o ),
i, key;
i = 0;
while ( (key = keys[i++]) ) {
f.apply( o[key], args );
}
};
if ( null == Object.keys ) {
fn = function ( f, args ) {
var o = this, p;
for ( p in o ) {
if ( o.hasOwnProperty(p) ) {
f.apply( this, args );
}
}
};
}
return function ( f, args ) {
fn.call( this, f, args );
};
} ());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment