我正在学习如何写一个自耕农发电机.我对以下代码有疑问.它通过添加var done = this.async()来说并且稍后在回调中调用该方法,我们可以使函数askFor()成为异步函数.有人可以解释一下原因吗?
askFor: function() { var done = this.async(); // Have Yeoman greet the user. this.log(yosay('Welcome to the marvelous Myblog generator!')); var prompts = [{ name: 'blogName',message: 'What do you want to call your blog?',default: 'myblog' }]; this.prompt(prompts,function(props) { this.blogName = props.blogName; done(); }.bind(this)); }
这是this.async的代码
this.async = function() { return function() {}; }
解决方法
原文地址:https://www.jb51.cc/nodejs/241151.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。