- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Edit Admin
Wait, isn't the first one just a non-terminated recursive method eating up stack till it runs out? I'm curious, because I never attempted to overload in JavaScript, I didn't even know that a redefinition doesn't result in an error.
Admin
One can have sort-of-overloading by type-testing on the duck-typed arguments - but it's not a great idea.
Edit Admin
It is, but it never gets called because:
Indeed. That's ... disappointing, but not entirely unsurprising. It's a bit like all the fun you can have in Python if you carelessly assign a new value to
self.frodo
whenself.frodo
exists and is (in theory) a function. The function object disappears and whatever you assigned takes its place.Luckily:
But also:
So Python does it, too.
Edit Admin
Just as i said yesterday that we have a leading candidate for upper management, competition emerged the very next day.
Edit Admin
The greasy pole has lotsa wannabe's scrabbling at the bottom. And more every day.
Edit Admin
That's pretty much every day in WTFLand.
Admin
I doesn't default unpassed in arguments to null, it defaults them to undefined. A similar value, but still distinct.
null !== undefined
,typeof undefined === "undefined"
, andtypeof null === "object"
are all true in JS.Admin
That the parser accepts it in the first place is heresy.
Like, in nested scopes why not. But declaring 2 functions with the same identifier in the same scope? The language shouldn't allow that. JS is TRWTF.
Edit Admin
JS is definitely very WTFy, but there isn't much choice - that's the language in all the browsers.
TRWTF is using JS on the server, or using languages like PHP - there are much better choices in that arena.
Edit Admin
Actually it defaults them to
undefined
. But that's also falsey, so the logic is the same.Edit Admin
That senior dev might be thinking of TypeScript, which on the surface does have operator overloading... but only until you compile it down to JavaScript, at which point yeah, it's gone.
Also, any number of tools would've caught that (ESLint, IDE's). Which makes one wonder what editor that senior dev was using.