Created
May 16, 2019 10:11
-
-
Save davidsharp/9184a2e501f5e6704717031bb4951312 to your computer and use it in GitHub Desktop.
An ill-advised console.log proxy allowing logging via `console.log = 'someValue'` (which actually gains some nice features)
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
| console=new Proxy(console,{set:(obj,prop,value)=>obj[prop](value)}) | |
| /* | |
| Use like: | |
| console.log = 'hello world' | |
| logs -> 'hello world' | |
| Unexpected bonus side-effect: | |
| const foobar = console.log = 'hello world' | |
| logs -> 'hello world' | |
| then!: | |
| console.log = foobar | |
| logs -> 'hello world' | |
| */ |
Author
Author
Also worth pointing out, console.log(foobar) would still work as expected, because the setter never actually sets anything, so console.log is always console.log
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Naturally, you can also set the proxy to be called something else, rather than setting it to
consoleand then use it likemyProxiedConsole.log = 'console is left untouched'