Git Product home page Git Product logo

Comments (4)

bathos avatar bathos commented on May 23, 2024

Thanks. I tried to nail this quick the other day since I only had a minute, and accidentally did params instead of args. Revising now.

from ecmascript-sublime.

barneycarroll avatar barneycarroll commented on May 23, 2024

Thanks! Incidentally, this reminded me how irritated I am that a leading rest operation is illegal in the first place. Don't suppose you've got any insight on why this is the case?

from ecmascript-sublime.

bathos avatar bathos commented on May 23, 2024

I bet there are ES Discuss records about that. Perhaps it would create some hidden complexity. Superficially, permitting a "rightward" mapping is not ambiguous:

function poop(...rest, last) {}
function poop(...rest, penultimate, last) {}

The first thing I can think of is that it does require some new grammar, because this, along with any other parameter declaration with two rests, is nonsensical:

function poop(...wat, ...no) {}

On the other hand, this is actually unambiguous:

function poop(first, ...middle, last) {}

So they could have written the grammar such that any given parameter declaration would contain zero or one rest parameters. I don't think this would have required any hoop jumping, actually -- no cover grammars or anything like that -- so I doubt grammatical complexity was the issue.

So perhaps it has something to do with how function parameters are implemented internally -- maybe it would be somehow disruptive that, if non-terminal rests were permitted, _non-_rest parameters would no longer have specific indices. But I'm just guessing here; for all I know, nobody brought it up? I'm pretty clueless about the internal mechanics for outfitting functions.

from ecmascript-sublime.

bathos avatar bathos commented on May 23, 2024

Other thoughts: In your own code, you can implement a simple util for supporting right-to-left rest-params. (More complex forms wouldn't be so easy to represent, though):

const reversedRest = fn => {
  const ln = fn.length;

  return (...args) => {
    const rest  = args.slice(0, -ln);
    const named = args.reverse().slice(0, ln);
    return fn(...named, ...rest);
  };
}

const example = reversedRest((tail, ...rest) =>
  `the tail is "${ tail }"; there are ${ rest.length } members prior (${ rest })`
);

console.log(example('a', 'b', 'c', 'd'));

On Babel REPL

from ecmascript-sublime.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.