Javascript调用函数并等待其返回

时间:2015-10-09 09:43:56

标签: javascript node.js function return

在node.js中的

我有一个函数A,其中我调用另一个函数B.函数B返回一个我需要在函数A中继续的数组。但是函数A不等待返回值并继续。如何管理函数A以等待函数B的返回值?

functionA(param1, param 2) {
      //some code
      var content = functionB(argument);
      //some more code which needs return of functionB
}

functionB(argument) {
      //some more code
      bot.page(t).complete(function (title, text, date) {
    var str = S(text).between('== Kurzbeschreibung ==\n* ', '.').s;
            var content = {};
            str = parseTitles(str); //calls antoher function which splits a long string into an array
            content.Owner = str[0];
            content.Aim = str[1];
            content.What = str[2];
            content.Who = str[3];
            content.Steps = str[4];
            content.Page = 'anyurl';
            return content;
        }
});

}

现在,函数A没有等到函数B完成并返回它的值。

0 个答案:

没有答案