Your mistake might be easier to spot with a function without arguments:
The right way:
Promise.resolve().then(setFirstKeyframe)
Above, the function setFirstKeyframe
is an argument to .then
, for the promise to call later.
The wrong way:
Promise.resolve().then(setFirstKeyframe())
Here, setFirstKeyframe
is called immediately (!), and its result (a promise) is passed to then
(which gets ignored as then
expects a function).
For functions with arguments use an anonymous function:
Promise.resolve().then(function() {
return setFirstKeyframe('keyframe-0');
})
This is where es6 arrow functions rock:
Promise.resolve().then(() => setFirstKeyframe('keyframe-0'))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…