Created
July 8, 2011 14:44
-
-
Save satyr/1071994 to your computer and use it in GitHub Desktop.
__lookup?etter__ in ES5
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
function lookup obj, key | |
if obj? | |
obj = Object obj | |
do | |
return that if Object.getOwnPropertyDescriptor(obj, key)?[@] | |
while obj = Object.getPrototypeOf obj | |
void | |
<[G S]>forEach -> Object"lookup#{it}etter" = lookup.bind it.toLowerCase() + \et |
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
(function(){ | |
function lookup(obj, key){ | |
var that, _ref; | |
if (obj != null) { | |
obj = Object(obj); | |
do { | |
if (that = (_ref = Object.getOwnPropertyDescriptor(obj, key)) != null ? _ref[this] : void 8) { | |
return that; | |
} | |
} while (obj = Object.getPrototypeOf(obj)); | |
} | |
} | |
['G', 'S'].forEach(function(it){ | |
return Object["lookup" + it + "etter"] = lookup.bind(it.toLowerCase() + 'et'); | |
}); | |
}).call(this); |
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
require \./lookup_etter | |
{strictEqual: eq} = require \assert | |
get = -> | |
set = -> | |
obj = Object.create null, p: {get, set} | |
eq get, Object.lookupGetter obj, \p | |
eq set, Object.lookupSetter obj, \p | |
eq get, Object.lookupGetter obj{} \p | |
eq set, Object.lookupSetter obj{} \p | |
eq void Object.lookupGetter {} \p | |
eq void Object.lookupGetter 42 \p |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment