我是功能编程的新手,有人建议lodash
了解主要的高阶函数。什么时候可以使用lodash.after()?
浏览lodash API文档,我把握不住sample code为_.after()
:
var saves = ['profile', 'settings'];
var done = _.after(saves.length, function() {
console.log('Done saving!');
});
_.forEach(saves, function(type) {
asyncSave({ 'type': type, 'complete': done });
});
// → logs 'Done saving!', after all saves have completed
上面的示例代码没有实行asyncSave()
,所以我应该实现的功能为自己。但我不知道如何实现它。这是因为我不明白_.after()
本身的规格。
如果有人比API文档更容易解释函数,那将会很棒。或者一个易于理解和实用的功能示例将是一个很大的帮助。谢谢!
感谢您的详细解释。你的例子比lodash API doc的例子更好理解。 – philipjkim