Created
April 4, 2012 10:50
-
-
Save brianewing/2300335 to your computer and use it in GitHub Desktop.
Javascript symbol-to-proc
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
String.prototype.__defineGetter__('proc', function() { | |
var prop = this; | |
return function(obj) { | |
if(typeof obj[prop] == 'function') | |
return obj[prop](); | |
return obj[prop]; | |
} | |
}); | |
// Usage: | |
var people = /* ... */; | |
people.map('name'.proc); // ["bob", "jill", ...} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment