Javascript 在使用alexa sdk的alexa技能中,我将如何使用http?

Javascript 在使用alexa sdk的alexa技能中,我将如何使用http?,javascript,node.js,this,Javascript,Node.js,This,我目前正在使用node.js,发送get请求时遇到问题。以下是我的请求: http.get("http://graph.facebook.com/v2.7", function(res) { res.on('data', function (chunk) { temp += chunk; }); res.on('end', function () { //Figure out how to not

我目前正在使用node.js,发送get请求时遇到问题。以下是我的请求:

 http.get("http://graph.facebook.com/v2.7", function(res) {
        res.on('data', function (chunk) {
            temp += chunk;
        });

        res.on('end', function () {
            //Figure out how to not use "this" keyword because it doesn't work....
            this.emit(":ask", toAsk, temp);
        });
}).on('error', function (e) {
   console.log("Got error: ", e);
});
如您所见,在结束回调中,我不能使用标准this.emit,因为它引用了该上下文中的其他内容。我有点搞不清楚该怎么解决这个问题。有人能帮忙吗


谢谢你

我相信这个问题是关于在回调中使用这个的,与提问无关

您可以在此处找到有关该问题的完整讨论:

解决这个问题的一个好办法是在回调函数中使用fat arrow函数语法

res.on('end', () => {
       // with this syntax, 'this' is same as in above (res.on) context.
       this.emit(":ask", toAsk, temp);
  });

非常感谢。我不知道那是件事!