Created
September 7, 2017 04:54
-
-
Save mastfissh/b0d1777715be8431935b9451aacee386 to your computer and use it in GitHub Desktop.
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
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