Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/456.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在Lambda函数中定义emit()属性_Javascript_Node.js_Aws Lambda_Amazon_Alexa - Fatal编程技术网

Javascript 如何在Lambda函数中定义emit()属性

Javascript 如何在Lambda函数中定义emit()属性,javascript,node.js,aws-lambda,amazon,alexa,Javascript,Node.js,Aws Lambda,Amazon,Alexa,我只是想让Alexa说出我谷歌电子数据表中的数据。我使用的是google spreatsheet node.js模块,而不是http.get()方法 这是我的意图函数 'GetPainterIntent': function() { // spreadsheet key is the long id in the sheets URL var doc = new GoogleSpreadsheet('1K-dl08g8s27TgF5yMGv_Q5tBbkpRpGWrt3RkUB

我只是想让Alexa说出我谷歌电子数据表中的数据。我使用的是google spreatsheet node.js模块,而不是http.get()方法

这是我的意图函数

'GetPainterIntent': function() {
        // spreadsheet key is the long id in the sheets URL 
var doc = new GoogleSpreadsheet('1K-dl08g8s27TgF5yMGv_Q5tBbkpRpGWrt3RkUB2mVKk');
var sheet;

async.series([
  function setAuth(step) {
    // see notes below for authentication instructions! 
    var creds = require('./creds.json');
    // OR, if you cannot save the file locally (like on heroku) 
    /*
    var creds_json = {
      client_email: ' ',
      private_key: ' '
    }
        */
    doc.useServiceAccountAuth(creds, step);

  },
  function getInfoAndWorksheets(step) {

    doc.getInfo(function(err, info) {
      console.log('Loaded doc: '+info.title+' by '+info.author.email);
      sheet = info.worksheets[0];

      //console.log('sheet 1: '+sheet.title+' '+sheet.rowCount+'x'+sheet.colCount);
      this.emit('ask:', 'Do you want'+sheet.title+' '+sheet.rowCount+'x'+sheet.colCount);
      step();
    });

  }

], function(err){
    if( err ) {
      console.log('Error: '+err);
    }
});

    } 
在执行结果:失败日志中,我得到的一个关键信息是

 {
 "errorMessage": "RequestId: 79ed1bc9-aaee-11e7-878b-5fe3ebd777ae 
 Process 
 exited before completing request"
 }

TypeError: Cannot read property 'emit' of undefined
at getInfoAndWorksheets (/var/task/index.js:51:9)
at /var/task/node_modules/async/dist/async.js:3853:24
at replenish (/var/task/node_modules/async/dist/async.js:946:17)
at iterateeCallback

emit中的属性是否未定义?或者你如何定义emit的属性,或者我读错了吗?

我认为问题在于你丢失了你的
这个
编码方式,可能是因为它使用了异步序列。在顶部用类似于
var self=this
的行保存
this
,然后改用
self.emit