Es6 Restify参数typeof throws错误

时间:2016-12-06 15:26:03

标签: javascript ecmascript-6

我是ES6的新手。只是想知道spread参数的typeof。 http://es6-features.org/#RestParameter 我不知道为什么我无法打印传播参数的typeof,有人可以解释原因。

请找到以下代码段:

function restify(...x){ 
    console.log(typeof (...x));
}
restify([1,2,3,5,]);

2 个答案:

答案 0 :(得分:0)

您应该仅在参数定义中使用扩展运算符

const restify = (...x) => {
  console.log(typeof x);
}

restify([1, 2, 3, 4, 5]);

将打印Object。我使用了constarrow functions这些也是ES6功能,请查看http://es6-features.org/

答案 1 :(得分:0)

使用typeof x

function restify(...x){ 
    console.log(typeof x);
}
restify([1,2,3,5,]);
相关问题