It's kind of amazing how you can go a couple of decades in a language and still find new things, fairly basic things you didn't know. TIL that the .length of a function reflects the # of named arguments in its signature. How did I not know?
-
-
Replying to @briankardell
quick clarification: the length only represents the number of normal named identifier params, from left to right -- count stops once it encounters a default param, a destructuring param, or a rest param. function foo(a, b, c = 3, ...d) {} foo.length; // 2
1 reply 3 retweets 23 likes -
Replying to @getify
yes, good caveat - I didn't think I could fit that in a tweet. The gist is that I had no idea that this was a property that meant anything related to named arguments
1 reply 0 retweets 2 likes -
-
Replying to @getify
Is there an important reason for your distinction here? I was using the terminology from the spec chapter 17 "Unless otherwise specified, this value is equal to the largest number of named arguments..."
1 reply 0 retweets 0 likes -
Replying to @briankardell
This is the commonly accepted distinction between the two terms:pic.twitter.com/u7Ce5hn3O1
2 replies 0 retweets 4 likes -
Replying to @getify @briankardell
Moreover, a "named argument" is a different thing entirely, in that in several languages (Scala, Obj-C, and even idiomatically JS), you can "name your arguments" at the call-site and have those mapped to params. for example: foo(someParam = 3, otherParam = 2);
1 reply 0 retweets 1 like -
Replying to @getify @briankardell
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
2 replies 0 retweets 4 likes -
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
Yet `arguments` is only available within the function body...
-
-
Replying to @mathias @briankardell
it wouldn't make any sense to inspect what **arguments** had been passed to a function other than inside the function while it's running. it couldn't have any arguments before a call, and keeping arguments afterwards would be a GC hazard and of dubious benefit. :)
0 replies 0 retweets 2 likesThanks. Twitter will use this to make your timeline better. UndoUndo
-
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.