Skip to content

Instantly share code, notes, and snippets.

@hanbzu
Created October 30, 2013 15:28
Show Gist options
  • Save hanbzu/7234563 to your computer and use it in GitHub Desktop.
Save hanbzu/7234563 to your computer and use it in GitHub Desktop.
JavaScript: Prop: Property of. Thanks to Christian Johansen.
// If I define the 'prop' function
function prop(name) {
return function (object) {
return object[name];
};
}
// Instead of this
var str = "Mentioned by " + tweeps.map(function (t) {
return t.name;
}).join(", ");
// I can do this
var str = "Mentioned by " + tweeps.map(prop("name")).join(", ");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment