How to use arrow function with || operator
问题 Using Babel, I can see that callback = () => {}; compiles to callback = function callback() {}; which is what I expect. However I get an error when I try to use it with || callback = callback || () => {} Which I'd expect to be equivalent to callback = callback || function(){}; Why is this an error? Also, is there a more correct ES6 version of this familiar syntax? 回答1: It fails because that is just not valid syntax. Use the following to make it work: callback = callback || (() => {}) If you