首页 > 其他 > 详细

多态性

时间:2020-04-26 22:00:30      阅读:67      评论:0      收藏:0      [点我收藏+]
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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!