On Fri, Sep 13, 2013 at 3:06 PM, Axel Rauschmayer <[email protected]> wrote:
>>> * You can have default parameters before parameters without defaults.
>>
>> The spec explicitly states that any parameter without a default, but after
>> another parameter that does have a default assignment implicitly has a
>> default property of undefined
>
> As an aside: This can be useful. For example:
>
> ```js
> function getRandomInteger(lower = 0, upper) {
>     return Math.floor(Math.random() * (upper - lower)) + lower;
> }
> ```
>
> Implementing this function in some other manner is much more complicated.

This doesn't do what you appear to think it does.  In particular,
calling it with "getRandomInteger(5)" is *not* equivalent to calling
it with "getRandomInteger(0, 5)", it's equivalent to calling it with
"getRandomInteger(5, undefined)".

This is precisely what the spec section you've quoted says, so I'm not
sure how you're confused on this point.

~TJ
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to