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

Use of splats in object destructuring #941

lorefnon opened this issue Nov 20, 2016 · 2 comments

Use of splats in object destructuring #941

lorefnon opened this issue Nov 20, 2016 · 2 comments


Copy link

@lorefnon lorefnon commented Nov 20, 2016

Current behavior when using splats while destructuring objects is non-intuitive (if not buggy):

x = ({name, age,}) -> 

Results in:

var x;
x = function(arg$){
  var name, age, rest;
  name = arg$.name, age = arg$.age, rest = import$({}, arg$.rest);
  return rest;
function import$(obj, src){
  var own = {}.hasOwnProperty;
  for (var key in src) if (, key)) obj[key] = src[key];
  return obj;

People coming from ES6 are likely to expect rest to include attributes other than name and age.

Analogous example using babel:

var x = ({a, b,}) =>

compiles to:

"use strict";

function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!, i)) continue; target[i] = obj[i]; } return target; }

var x = function x(_ref) {
  var a = _ref.a,
      b = _ref.b,
      rest = _objectWithoutProperties(_ref, ["a", "b"]);

  return console.log(rest);

Is there a rationale behind the current behavior ?

Copy link

@rhendric rhendric commented Nov 20, 2016

I've scratched my head at this one before; would like to hear other opinions but personally I'd be happy to call this a bug.


Copy link

@summivox summivox commented Nov 21, 2016

Good catch! I don't think there is any rationale for current behavior either.

Nitpick: the _objectWithoutProperties impl could have used an object instead of an array of strings


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

Successfully merging a pull request may close this issue.

None yet
3 participants