function ask(question, ...handlers) { let isYes = confirm(question); for(let handler of handlers) { if (handler.length == 0) { if (isYes) handler(); } else { handler(isYes); } } } // 对于积极的回答,两个 handler 都会被调用 // 对于负面的回答,只有第二个 handler 被调用 ask("Question?", () => alert(‘You said yes‘), result => alert(result));
原文:https://www.cnblogs.com/LangZ-/p/12782123.html