Skip to content

Instantly share code, notes, and snippets.

@0x1mason
Last active August 29, 2015 14:09
Show Gist options
  • Save 0x1mason/2709de49b8b8ef85ccd6 to your computer and use it in GitHub Desktop.
Save 0x1mason/2709de49b8b8ef85ccd6 to your computer and use it in GitHub Desktop.
// in helpers.js
Object.prototype.forOf = function(iterateFunc) {
var keys = Object.keys(this),
continueLoop = true;
var breakLoop = () => continueLoop = false;
for(var counter = 0; counter < keys.length && continueLoop; counter++) {
iterateFunc(this, keys[counter], breakLoop);
}
};
// for/of analog
myItems.forOf((items, key, breakLoop) => {
if (items[key] === foo) {
items[key] = "bar";
breakLoop();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment