Skip to content

Instantly share code, notes, and snippets.

@gyula-ny
Created November 23, 2017 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gyula-ny/be83a37ee13ba229972b9d5141e7c0b1 to your computer and use it in GitHub Desktop.
Save gyula-ny/be83a37ee13ba229972b9d5141e7c0b1 to your computer and use it in GitHub Desktop.
returns [value, exists] tuple for object property access
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