我是ES6的新手。只是想知道spread参数的typeof。 http://es6-features.org/#RestParameter 我不知道为什么我无法打印传播参数的typeof,有人可以解释原因。
请找到以下代码段:
function restify(...x){
console.log(typeof (...x));
}
restify([1,2,3,5,]);
答案 0 :(得分:0)
您应该仅在参数定义中使用扩展运算符
const restify = (...x) => {
console.log(typeof x);
}
restify([1, 2, 3, 4, 5]);
将打印Object
。我使用了const
和arrow functions
这些也是ES6功能,请查看http://es6-features.org/
答案 1 :(得分:0)
使用typeof x
。
function restify(...x){
console.log(typeof x);
}
restify([1,2,3,5,]);