Created
November 23, 2017 09:49
-
-
Save gyula-ny/be83a37ee13ba229972b9d5141e7c0b1 to your computer and use it in GitHub Desktop.
returns [value, exists] tuple for object property access
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 handler = { | |
get: function(target, name) { | |
if (name in target) { | |
return [target[name], true] | |
} else { | |
return [null, false] | |
} | |
} | |
}; | |
module.exports = function(obj) { | |
return new Proxy(obj, handler); | |
} | |
// const v = require("./verboseObject"); | |
// const [value, exists] = v(obj).someProperty; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment