Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/39.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 如何在Node.js中将变量从一个函数传递到另一个函数?_Javascript_Node.js_Bots_Azure Language Understanding - Fatal编程技术网

Javascript 如何在Node.js中将变量从一个函数传递到另一个函数?

Javascript 如何在Node.js中将变量从一个函数传递到另一个函数?,javascript,node.js,bots,azure-language-understanding,Javascript,Node.js,Bots,Azure Language Understanding,我想将topic_to_learn变量传递给第二个函数,并在第二个函数中用于其他用途 函数(会话、参数、下一步){ var topic_to_learn=builder.EntityRecognizer.findEntity(args.entities,“topic_to_learn”); builder.Prompts.text(会话“当然可以,你能告诉我你的目标吗,或者在学习了这个主题后你想实现什么吗?”); }, 功能(会话、结果、下一步){ var学习目标=结果。响应; session.

我想将
topic_to_learn
变量传递给第二个函数,并在第二个函数中用于其他用途

函数(会话、参数、下一步){
var topic_to_learn=builder.EntityRecognizer.findEntity(args.entities,“topic_to_learn”);
builder.Prompts.text(会话“当然可以,你能告诉我你的目标吗,或者在学习了这个主题后你想实现什么吗?”);
},
功能(会话、结果、下一步){
var学习目标=结果。响应;
session.send('明白了,让我想想…',session.message.text);
session.send('Voila!这些是与'+topic\u to\u learn,session.message.text'相关的文章);
},

您可能希望使用上述范围内的变量,该变量可用于两个函数

   var topic_to_learn;

    function (session, args, next) {
        topic_to_learn = builder.EntityRecognizer.findEntity(args.entities, 'topic_to_learn');
        builder.Prompts.text(session, 'Sure, can you please also tell me about your goals or anything you want to achieve after learning about this topic?');
    };

    function (session, results, next) {
        var learning_goals = results.response;
        session.send('Got it, let me think...', session.message.text);
        session.send('Voila! These are the articles related to ' + topic_to_learn, session.message.text);
    },

非常感谢…我也试过了,但失败了,似乎我不能这样写,因为这两个函数似乎存储在另一个函数中…匹配('get_learning_plan',[function(会话,参数,下一步)]{…最好的方法是为所有3个函数创建一个模块,并在后续函数中串行地要求它们。这样,您可以像访问对象属性一样访问函数中的变量(func1.topic_to_learn)嘿,伙计,我正在使用另一个库,这就是为什么我的代码看起来有点奇怪,但你的回答确实启发了我,我刚刚找到了另一种解决方法,非常感谢!请提供完整的代码或至少一个。这两个函数表达式之间带有逗号,单独运行时是语法错误。它们是否相互调用?这完全是错误的不清楚它们是如何使用的。非常感谢,你所有的答案都启发了我,我找到了方法,非常感谢!!这是一个答案吗?
.matches('get_learning_plan', [

        function (session, args, next) {
            var topic_to_learn = builder.EntityRecognizer.findEntity(args.entities, 'topic_to_learn');
            builder.Prompts.text(session, 'Sure, can you please also tell me about your goals or anything you want to achieve after learning about this topic?');
        },
        function (session, results, next) {
            var learning_goals = results.response;
            session.send('Got it, let me think...', session.message.text);
            session.send('Voila! These are the articles related to ' + topic_to_learn, session.message.text);
        },