News for hackers. Stuff that matters.
Re:The Birth and Death of JavaScript [video] by briantakita on Friday April 18, 2014 @03:38AM (#7608320)
It's only WTF because it's not the same as other implementations of map. Once you can internalize the map implementation, it's no longer WTF & actually makes sense.
Re:The Birth and Death of JavaScript [video] by meowface on Friday April 18, 2014 @06:36AM (#7608688)
It makes sense but it still strongly violates the principle of least surprise. No other language I know of does this, nor do I think this would be a particularly desirable feature.
Re:The Birth and Death of JavaScript [video] by rplnt on Friday April 18, 2014 @04:43AM (#7608482)
That's the weird part. Why does array provide three arguments? But I agree, that's something you can learn. I guess.

But it's WTF anyway. I have a function that takes either one or two arguments, I provide three, and everyone seems to be OK with that.

Re:The Birth and Death of JavaScript [video] by just2n on Friday April 18, 2014 @05:10PM (#7611346)
Well that decision is pretty necessary when you realize that JS has no syntax to indicate a function is variadic (we use the arguments magic variable, but use of it does not necessarily indicate that a function is variadic) and that implementation supplied functions are not required to have their arity exposed via Function.prototype.length (http://es5.github.io/#x15.3.5.1).

There's no way to know, even at run-time, whether a function is being called with too few or too many arguments, since that's equivalent to the halting problem. So the sensible alternative is just to default everything to undefined, and silently ignore extraneous arguments.

But yes, if JS was strict with how it handled argument definition lists and had support for indicating infinite arity, I'd agree, this would be a WTF, or at least strange. But I think it makes a lot of sense, all things considered.

Re:The Birth and Death of JavaScript [video] by gnuvince on Friday April 18, 2014 @10:07AM (#7609166)
So much for abstraction if you need to understand the implementation of every function you'll every use in JavaScript.
Re:The Birth and Death of JavaScript [video] by yourad_io on Friday April 18, 2014 @10:39AM (#7609297)
> understand the implementation of every function

Rather: remember three things that make up the majority of Array iterators' callback functions' signatures:

Element, Index, Array.

Shared by: .map, .every, .forEach, .filter, and probably some that I am forgetting. The exception I think is just .reduce[Right], which by definition requires its previous return value, so you have (retVal, elem, i, arr).

Quite literally, if you remember .map callback, you remember .every callback :)

Javascript deserves shtick for its truly bad parts (with, arguments, ...) and some missing parts, but .map and its friends aren't it.