On Feb 21, 2014, at 1:47 PM, C. Scott Ananian wrote: > I wasn't confused by the spec text as is, but I'm not surprised that > others are. The language is battling against two different "standards" > for optional arguments. In ES5 typically "not present" is used; in ES6 > for consistency with the new language optional arguments, "undefined" > is treated as "not present" and `arguments.length` is ignored.
This really isn't correct. It has always been the case that arguments that are not explicitly included in the actual argument list are automatically initialized to undefined. Most spec. (ES3, ES5, Es6, etc.) references to arguments simply reference them by name and don't worry about whether or not an argument has the value undefined because it was explicitly passed by the called or if it was default to undefined by the language semantics. There are a few functions and methods, some of them dating back to least ES3 that treat a explicit undefined value differently from a missing argument value. In ES5 "in pressent" or "not passed" is used to explicitly identify such cases. There are also few places where either the ES3 spec. did not match the web reality that browsers have implemented for situations where argument values were not explicitly passed.. Most of those were corrected in ES5, ES6 makes a fix in this regard for Array.prototype.splice. Compare http://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.prototype.splice to the definition in ES5 and not that ES5 does not have the equivalent to steps 9 and 10. There is no general change of style for new ES6 built-in regarding the handling of arguments that are not explicitly passed and the specification of built-in methods do not depend upon default parameter value initialization (that's a ES language feature but built-ins are not necessarily implemented using ES). There are cases where ES6 parameter default value initialization an be used to describe the legacy behavior but that isn't a change of behavior from ES5 or ES3. > > This issue arose in a discussion with the `bluebird` maintainer about > the proper semantics for `Promise.reduce`; he wanted to use "ES6 > style" for the final optional argument (which meant that you can't use > `undefined` as an `initialValue`), while I wanted "ES5 style" to be > consistent with the ES5 method `Array#reduce`. If Proimise.reduce is supposed to be similar to Array.prototype.reduce then I'd recommend using exactly the same argument conventions for. > > It might be worth coming up with good terms for "ES5-style optional > arguments" and "ES6-style optional arguments" which can be used > consistently in the spec. They can already be distinguished by > signature, ie: > > ```js > Array.prototype.reduce ( callbackfn [ , initialValue ] ) > Array.prototype.splice (start, deleteCount [ , item1 [ , item2 [ , … ] ] ] ) > ``` > > versus > > ```js > Array.prototype.fill (value, start = 0, end = this.length) > Array.prototype.copyWithin (target, start, end = this.length) > ``` Don't put too much weight into that. I've experiment with use the latter style when define some new methods to see where it is helpfully more descriptive. I just haven't bother to update all the legacy methods to use that same style. At some point in the near future I wall make a pass over the entire document and use consistent conventions for all function signatres -- either the ES3/5 style or the default value style. Given the amount of confusion the new style seems to have case, I may well revert to using the ES3/5 style. > > Another alternative might be to define a helper function used wherever > "ES5-style" optional arguments were used. I summary, there is no actual differences in style. ES functions have always used undefined as the default value of formal parameters that do not have an explicit corresponding actual argument in the call. Functions that what to provide some other treatment for such missing arguments have always had to deal with that situation explicitly. All Es6 really adds in this regard is a short and for saying: if (parameterN===undefined) paramaterN=expr; Allen
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

