Heroku 说:SyntaxError: Unexpected token ...
如何调整此功能以与 heroku 兼容?
authenticate(...args) {
var authRequest = {};
authRequest[Eureca.Protocol.authReq] = args;
this.socket.send(this.serialize(authRequest));
}
我对 Heroku 不是很熟悉,但您始终可以执行以下操作。 Array.prototype.slice.call(arguments)
将实现与在这种情况下使用 rest 运算符相同的效果。
authenticate() {
const args = Array.prototype.slice.call(arguments);
var authRequest = {};
authRequest[Eureca.Protocol.authReq] = args;
this.socket.send(this.serialize(authRequest));
}
查看示例。
function foo1(...args) {
console.log(args);
}
function foo2() {
const args = Array.prototype.slice.call(arguments);
console.log(args);
}
foo1(1, 2, 3, 4);
foo2(1, 2, 3, 4);
而这段代码是通过babel转译器运行foo1
函数得到的。
function foo1() {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
console.log(args);
}