in JS, we do that idiomatically with object literals and object param destructuring: function foo({ someParam, otherParam }) { .. } // named params foo({ otherParam: 2, someParam: 3 }); // named args
-
-
Replying to @getify @briankardell
Counterargument: the arguments object
2 replies 0 retweets 0 likes -
Replying to @mathias @briankardell
actually, I think the `arguments` object is a confirmation of these. The `arguments` object/array holds all the values that were passed in as **arguments**. It's a very nuanced and frowned-upon strange'ness that there's a deep reference from the arguments entry to the param.
2 replies 0 retweets 2 likes -
I always teach it this way, that the `arguments` array is holding the argument values, irrespective of any params which also might be holding them by name.
1 reply 0 retweets 1 like -
Replying to @getify @briankardell
That explanation breaks down in the face of the shadowing behavior. function foo(a, b) { a = 9; b = 8; console.log(arguments); } foo(1, 2);
1 reply 0 retweets 1 like -
Replying to @mathias @briankardell
I know about the shadowing and I mentioned it in my earlier tweet ("...deep reference..."). but i think my assertion stands, given that nobody in their right mind uses that intentionally, and strict mode eliminated it. I'd wager > 99% have never even heard of or considered it.
3 replies 0 retweets 2 likes -
Uses what? Reassigns function arguments? Or arguments containing references to params? Either way, the shadowing is something good to know.
2 replies 0 retweets 0 likes -
> "uses what"? I'm saying nobody intentionally reassigns an argument and then also relies on that having changed the entry in the `arguments` object/array. If they do, that's terribly confusing code.
1 reply 0 retweets 0 likes -
Yea, I'd guess more often it'd be "they reassign an argument and expect for it *not* to have been changed in `arguments`", hence better to know about that behavior.
2 replies 0 retweets 0 likes -
I think better than teaching such a strange unpredecented wart of long-ago historical heritage, is to just teach not to use `arguments` anymore, in favor of ...rest parameter (which is a real array). Frankly, I only endorse `arguments.length`, and even then, only in rare cases.
2 replies 0 retweets 2 likes
We’re in agreement on that!
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
JavaScript, HTML, CSS, HTTP, performance, security, Bash, Unicode, i18n, macOS.