NodeJs-函数内部的访问变量

因此,基本上,我正在使用 node-url-shortener 库来缩短链接,但是,在使用该函数之后,我想将新的缩短的链接(shortenedUrl)传递给函数之外,然后将其记录在控制台中。

如果我将console.log放在函数中,它的日志记录就很好了,但是显然那不是我要在这里实现的目标...

这是我这样做的尝试:

const shortUrl = require('node-url-shortener');

var shortenedUrl;

shortUrl.short('www.google.com',function(err,shortUrl){
  shortenedUrl = shortUrl;
  // do somemthing here to pass the shortenedUrl outside the function
});

console.log(shortenedUrl);

感谢您的任何帮助,并在此先感谢您!

swj1363345 回答:NodeJs-函数内部的访问变量

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3160781.html

大家都在问