【发布时间】:2020-03-08 20:34:10
【问题描述】:
我有几个要听的事件。第二个事件html.set 中的函数取决于第一个事件initialised 中的函数先完成。我想出了一个使用承诺的解决方案,但感觉很脏。我想知道这是否是最好的方法?
var applyGoogleFonts = new Promise(function(resolve, reject) {
editor.events.on('initialized', function() {
_applyGoogleFonts().then(resolve);
});
});
editor.events.on('html.set', function() {
applyGoogleFonts.then(_setThemeFonts);
});
我应该补充一点,_setThemeFonts 取决于 html.set 的触发器首先完成之前的代码。
【问题讨论】:
标签: javascript