Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rest parameters and default parameters #1779

Closed
MartinKolarik opened this issue Jul 24, 2014 · 11 comments
Closed

Rest parameters and default parameters #1779

MartinKolarik opened this issue Jul 24, 2014 · 11 comments

Comments

@MartinKolarik
Copy link

JSHint reports Regular parameters cannot come after default parameters if you use both default parameter and rest parameter, but I think this is a valid use case:

function f (x = 0, ...y) {}
@Nicolab
Copy link

Nicolab commented Nov 13, 2014

Hello,

+1

main.expr.parse = function parse(expression = '', scope) {
};

Regular parameters cannot come after default parameters

An idea to fix this ?

@rwaldron
Copy link
Member

Sorry, lost track of this one, thanks for the bump.

@Nicolab
Copy link

Nicolab commented Nov 15, 2014

Super :)

@UltCombo
Copy link

UltCombo commented Jan 7, 2015

Should the "Regular parameters cannot come after default parameters" error even exist at all?

AFAIK this is valid:

function f(a = 1, b) {
    console.log(a, b); // 1, 2
}
f(undefined, 2);

Yet JSHint throws the aforementioned error.

@caitp
Copy link
Member

caitp commented Jan 7, 2015

@UltCombo
Copy link

UltCombo commented Jan 7, 2015

It could be downgraded to a warning/config option IMO (e.g. useful for people that consider it a bad practice).
But it is not much of a choice when you're passing callbacks to 3rd-party APIs.

@UltCombo
Copy link

UltCombo commented Jan 7, 2015

If downgrading to a warning/config is preferred, I guess a new issue should be opened to track the progress on it.

If the error is removed altogether, then it fixes both OP's and my issue.

@caitp
Copy link
Member

caitp commented Jan 7, 2015

ever since at least draft rev 20 (from 10/2013), the workings have been "initializers can go anywhere, and just replace undefined values". I don't have any older drafts, so maybe this was different at some point. Anyways, we should probably just delete the warning, it's kinda bogus

@caitp
Copy link
Member

caitp commented Jan 7, 2015

@rwaldron wdyt?

@rwaldron
Copy link
Member

rwaldron commented Jan 7, 2015

There are two things here:

  1. Formal rest parameters are restricted to last position.
  2. There is no restriction on defaults

@lukeapage
Copy link
Member

Any preference on whether to convert to a warning or remove outright ?

Not sure what you mean by There is no restriction on defaults but if its that function(a = b,b){} fails, that is covered in other issues (and fixed in a PR)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants