zoukankan      html  css  js  c++  java
  • JS 设计模式七 -- 外观模式

    概念

    为子系统中的一组接口提供一个一致的界面,定义一个高层接口,这个接口使子系统更加容易使用。

    外观模式在JS中,可以认为是一组函数的集合。

    实现

    // 三个处理函数
    function start() {
        console.log('start');
    }
    
    function doing() {
        console.log('doing');
    }
    
    function end() {
        console.log('end');
    }
    
    // 外观函数,将一些处理统一起来,方便调用
    function execute() {
        start();
        doing();
        end();
    }
    
    
    // 调用init开始执行
    function init() {
        // 此处直接调用了高层函数,也可以选择越过它直接调用相关的函数
        execute();
    }
    
    init(); // start doing end
  • 相关阅读:
    随机数
    质数
    猜数
    失败
    判断质数
    2019.7.21记录
    9*9乘法表
    小人
    奔跑的字母

  • 原文地址:https://www.cnblogs.com/gaosirs/p/10750590.html
Copyright © 2011-2022 走看看