Skip to content

Instantly share code, notes, and snippets.

@cgatian
Last active December 28, 2015 07:49
Show Gist options
  • Save cgatian/7466919 to your computer and use it in GitHub Desktop.
Save cgatian/7466919 to your computer and use it in GitHub Desktop.
Reusable function for scoping issues when invoking functions in JavaScript.
var arrayForEach = function (array, action)
{
for (var i = 0, j = array.length; i < j; i++)
{
action(array[i]);
}
};
//Usage
arrayForEach(things, function(thing)
{
button.addEventListener("click", function()
{
thing.activate();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment