Last active
November 27, 2018 21:08
-
-
Save cessor/e19c96ae685f000ef8d7a820e2de1783 to your computer and use it in GitHub Desktop.
JS Proxy Stub
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
class Pseudo { | |
constructor(value) { | |
return new Proxy({}, { | |
get: () => value | |
}) | |
} | |
} | |
const callable = new Pseudo(10) | |
console.log(callable.someMethod()) // 10 | |
console.log(callable.anotherMethod()) // also 10 | |
const plainObject = new Pseudo(10) | |
console.log(plainObject.someProp) // 10 | |
console.log(plainObject.anotherProp) // guess what |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment