环境: Node.js v7.2.0
我正在尝试使用async
关键字创建返回承诺的方法。
我收到以下错误:
SyntaxError:意外的令牌功能
this.getFrame = async function(data) {
^^^^^^^^
这里是示例:
function Parser() {
this.receiveBuffer = Buffer.alloc(0);
this.frameBuff = Buffer.alloc(0);
/* GET FRAME ******************************** */
this.getFrame = async function(data) { //The ERROR appears here!!!
for (let byte of data) {
if (byte !== 0x0d && byte !== 0x0a) {
// console.log()
this.receiveBuffer = Buffer.concat([
this.receiveBuffer,
Buffer.from([byte])
]);
// console.log("Buffer is long: " + this.receiveBuffer.length);
} else {
this.frameBuff = this.receiveBuffer;
this.receiveBuffer = Buffer.alloc(0);
// console.log(this.frameBuff);
return this.frameBuff;
}
}
};
/* ******************************** */
this.parse = function(frame) {
console.log(frame);
};
}