r/javascript • • Dec 16 '18

Coming from Python to JS NSFW

const print = console.log

I found my safe space.

607 Upvotes

156 comments sorted by

View all comments

Show parent comments

37

u/loopsdeer Dec 17 '18 edited Dec 17 '18

Shouldn't that err? I think you need console.log.bind(console). On mobile, can't test. I just don't want to give Java'rs anymore ammunition

Edit: Wow I've never been more excited to be wrong and to be down-voted. I'm not sure when this bug was fixed, but FOREVER this would have caused Illegal Invocation error. If you don't believe me, just search "console.log illegal invocation". Another one to throw on the "well, in my day..." pile. Yay!

20

u/[deleted] Dec 17 '18 edited Dec 17 '18

Stop downvoting him, assholes.

This didn't work without binding up until, if I'm not mistaken, Node.js 8.x. I don't remember it causing any errors, if I remember correctly it used to silently fail (i.e. not print anything because the log function would simply log to global).

Then at some point log() didn't depend on console being it's this. I've never seen a single sentence of explanation why this was changed, I've never used this kind of aliasing in browser so I'm not even sure it's a Node.js console implementation bug or a V8 bug, nor how Firefox behaved before (doesn't need bind() now).

So he was right.

Edit: Ah, yes, just needed to scroll down and find another post re the same thing and presto:

https://chromium.googlesource.com/chromium/src.git/+/807ec9550e8a31517966636e6a5b506474ab4ea9

3

u/loopsdeer Dec 17 '18

Aw thanks for the defense! Ya I looked through the chromium and firefox bugs and it looks like these have been very quietly resolved within the past year and a half.

But as I said in my edit, this is just one more thing on the "in my day" category now. For those of us using JavaScript since before jQuery, that category is quite huge and ever-growing. It's actually kind of delightful to be wrong in this way.

2

u/kingocad Dec 17 '18

My favourite “in my day” was this IE6 bug that caused IE6 to lose the name attribute when manipulating form dom elements, they would never submit but would be visible in the developer toolbar. Trying to track this down pre-stackoverflow was a nightmare!

I still have PTSD form that one!