简体   繁体   English

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

[英]How to pass variable from one function to another function in Node.js?

I want to pass the topic_to_learn variable to the second function and use it in the second function for something else. 我想将topic_to_learn变量传递给第二个函数,并在第二个函数中将其用于其他用途。

    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);
    },

You may want to use an above-scoped variable, available to both the functions. 您可能想使用两个函数都可以使用的作用域以上的变量。

   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);
    },
.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);
        },

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

相关问题 如何将函数从一个文件导出到另一个 node.js? - how to export a function from one file to another node.js? 将一个函数的结果用作另一个函数的变量-node.js - Using result of one function as a variable in another - node.js 如何将变量传递给node.js中的预定义回调函数 - How to pass a variable to a predefined callback function in node.js Node.js从另一个函数访问变量的值 - Node.js access the value of variable from another function 如何将变量从发布请求传递给在 Node.js 中将参数作为字符串或字符串数​​组的函数? - How to pass a variable from a post request to a function that takes params as string or array of string in Node.js? 如何从Android客户端传递node.js中的回调函数 - how to pass the callback function in node.js from android client 如何将变量从Jade传递到Node.js端点函数 - How to pass variables from Jade to Node.js endpoint function 如何将功能从Node.js服务器传递给客户端 - How to pass function to client from Node.js server 如何将参数从一个页面 function 传递到另一个页面 class function 在 Z9E13B69D1D715A927102ACAAAF14Z - how to pass parameter from one page function to another page class function in Javascript / Node js 将变量从一个函数传递到另一个函数 - Pass variable from one function to another function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM