MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/javascript/comments/a6txtp/coming_from_python_to_js/ebyl20o/?context=3
r/javascript • u/chroner • Dec 16 '18
const print = console.log
I found my safe space.
156 comments sorted by
View all comments
84
you need to use bind so the log function keeps the context of console.
const print = console.log.bind(console)
1 u/bart2019 Dec 17 '18 Except, console doesn't care, afaik. 7 u/theXpanther Dec 17 '18 It does, there was a stack overflow question about someone forgetting to bind 6 u/maple3142 Dec 17 '18 I think it depends on your javascript engine version. http://www.reddit.com/r/javascript/comments/a6txtp/-/eby144i 3 u/minuskruste Dec 17 '18 It depends on the context. It also won’t throw an error but it won’t work in some cases either. Particularly if you pass console.log as a function to a tap in an observable pipe.
1
Except, console doesn't care, afaik.
7 u/theXpanther Dec 17 '18 It does, there was a stack overflow question about someone forgetting to bind 6 u/maple3142 Dec 17 '18 I think it depends on your javascript engine version. http://www.reddit.com/r/javascript/comments/a6txtp/-/eby144i 3 u/minuskruste Dec 17 '18 It depends on the context. It also won’t throw an error but it won’t work in some cases either. Particularly if you pass console.log as a function to a tap in an observable pipe.
7
It does, there was a stack overflow question about someone forgetting to bind
6
I think it depends on your javascript engine version. http://www.reddit.com/r/javascript/comments/a6txtp/-/eby144i
3
It depends on the context. It also won’t throw an error but it won’t work in some cases either. Particularly if you pass console.log as a function to a tap in an observable pipe.
84
u/uberpwnzorz Dec 17 '18
you need to use bind so the log function keeps the context of console.
const print = console.log.bind(console)