Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Use of splats in object destructuring #941

Copy link
Copy link
@lorefnon

Description

@lorefnon
Issue body actions

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

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

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 (own.call(src, 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, ...rest}) =>
  console.log(rest)

compiles to:

"use strict";

function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, 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 ?

determin1st, summivox, rhendric, dk00 and foxbunny

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.