Hvordan passere variabel fra en funksjon til en annen funksjon i node.js?

stemmer
0

Jeg ønsker å sende topic_to_learnvariabel til den andre funksjonen og bruke det i den andre funksjonen for noe annet.

    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);
    },
Publisert på 19/03/2017 klokken 16:09
kilden bruker
På andre språk...                            


2 svar

stemmer
0
.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);
        },
Svarte 19/03/2017 kl. 16:22
kilden bruker

stemmer
0

Det kan være lurt å bruke en over-omfang variabel, tilgjengelig for både funksjonene.

   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);
    },
Svarte 19/03/2017 kl. 16:19
kilden bruker

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more