Created
September 18, 2015 16:25
-
-
Save dfadler/35a0748d990d09609d47 to your computer and use it in GitHub Desktop.
Expressive Code
This file contains hidden or 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 a = [{ | |
name:'fluffy', | |
age: 23, | |
run: function() { | |
// does something | |
} | |
}, { | |
name:'gunny', | |
age: 31, | |
run: function() { | |
// does something | |
} | |
}]; | |
// Not very expressive | |
for(var i = 0, len = a.length; i < len; i++) { | |
if(a[i].name === 'gunny') { | |
a[i].run(); | |
} | |
} | |
// More expressive | |
a.forEach(function(animal) { | |
if(animal.name === 'gunny') { | |
animal.run(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment