繁体   English   中英

为什么会出现SyntaxError:意外标识符?

[英]Why am I getting SyntaxError: Unexpected identifier?

很抱歉提出这样愚蠢的问题,但我花了一些时间在这个问题上,并期待着其他类似的问题,但这些问题都没有帮助

我在var Tools = module.exports定义了一个函数,并且不知道此函数定义出了什么问题:

getLastNRows: function (whereIsData, DB_info, table, NRows, callback) {
  if (whereIsData == "MySQL") {
    var queryString = "SELECT timestamp, temp1, temp2, temp3, temp4, level_ice_bank, flow, power, level_change_rate FROM " +
                      table + " ORDER BY id DESC LIMIT " + NRows + ";";
    var connnection = mysql.createConnection(DB_info);
    connnection.connect(function(err) {
      if (err) {
        console.log("Couldn't connect to the required MySQL DB.");
        console.log("DID NOT GET LAST " + NRows + " ROWS");
        throw err;
      }
    });
    connnection.query(queryString, function (err, rows) {
      if (err) {
        console.log("DID NOT GET LAST " + NRows + " ROWS");
        throw err;
      }
      Tools.setValue(rows);
      Tools.dataArray2Object(Tools.result_arr);
      callback();
    });
  }
  else {
    console.log("Function doesn't accept this DB service.\n(u still have to improve...)");
    return;
  }
 },

我越来越:

      getLastNRows: function (whereIsData, DB_info, table, NRows, callback) {
  ^^^^^^^^^^^^
 
SyntaxError: Unexpected identifier

也许有人在这里发现错误?

我认为这是一个对象,并且您刚发布第一行之前就错过了逗号:

var myMethods = {
  foo: function () {}, // < This comma
  getLastNRows: function (whereIsData, DB_info, table, NRows, callback) {
      ...
  },
};

当您遇到语法错误时,这意味着语法有问题(程序甚至无法执行)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM