Last active
December 28, 2015 07:49
-
-
Save cgatian/7466919 to your computer and use it in GitHub Desktop.
Reusable function for scoping issues when invoking functions in JavaScript.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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