-
Notifications
You must be signed in to change notification settings - Fork 155
Closed
Description
Current behavior when using splats while destructuring objects is non-intuitive (if not buggy):
x = ({name, age, ...rest}) ->
restResults 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
Labels
No labels