Skip to content

devsnek/proposal-unused-function-parameters

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Unused Function Parameters

The Problem

doSomething((unused1, unused2, somethingUseful) => {
  doSomethingWith(somethingUseful);
});

doSomething((_, __, somethingUseful) => {
  doSomethingWith(somethingUseful);
});

Solutions

Elisions

doSomething(( , , somethingUseful) => {
  doSomethingWith(somethingUseful);
});
  • Matches with existing destructuring
    • ([, c]) is already valid
  • Some might say it looks weird

Placeholder Syntax

doSomething((?, ?, somethingUseful) => {
  doSomethingWith(somethingUseful);
});

doSomething((*, *, somethingUseful) => {
  doSomethingWith(somethingUseful);
});

// etc.
  • Most explicit, clearly "using up" a parameter without binding it
  • Requires more syntax

Placeholder Identifier

doSomething((_, _, somethingUseful) => {
  doSomethingWith(somethingUseful);
});

doSomething((_, _, somethingUseful) => {
  print(_); // IdentifierReference : `_` early error?
  doSomethingWith(somethingUseful);
});
  • Arguably most natural, other languages use this (C#, Rust, etc.)
  • Any valid identifiers are already valid identifiers, could conflict with existing code

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages