Skip to content

Instantly share code, notes, and snippets.

@cessor
Last active November 27, 2018 21:08
Show Gist options
  • Save cessor/e19c96ae685f000ef8d7a820e2de1783 to your computer and use it in GitHub Desktop.
Save cessor/e19c96ae685f000ef8d7a820e2de1783 to your computer and use it in GitHub Desktop.
JS Proxy Stub
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