我正在学习如何写一个自耕农发电机.我对以下代码有疑问.它通过添加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() {};
- }