Skip to content

Instantly share code, notes, and snippets.

@mastfissh
Created September 7, 2017 04:54
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 mastfissh/b0d1777715be8431935b9451aacee386 to your computer and use it in GitHub Desktop.
Save mastfissh/b0d1777715be8431935b9451aacee386 to your computer and use it in GitHub Desktop.
const Undefined = new Proxy({}, {
get: function(target, name){
if (name == '$'){
return undefined
} else {
return Undefined;
}
}
});
let safeAccess = {
get: function(target, name) {
if (name == '$'){
return target
}
if (name.endsWith('$')) {
if (typeof target[name] === 'undefined'){
return Undefined;
} else {
let new_command = name.substring(0, name.length - 1);
return new Proxy(target[new_command], safeAccess)
}
}
return target[name]
}
}
let raw_thing = {}
let thing = new Proxy(raw_thing, safeAccess);
console.log('first')
console.log(thing.foo$.bar$.baz$.$)
if (thing.foo$.bar$.baz$.$){
console.log('failed')
}
console.log('second')
console.log(thing.foo$.bar$[0].baz$.blo$.$)
process.exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment