js.pattern -h 策略模式

2016-07-15  本文已影响0人  许道龙

策略比状态模式 少了一个储存状态的类

'use strict'

let PriceStrategy = (function () {
    class strategy {
        constructor() {
            let that = this;
            this.change = {
                return30: () => {

                },
                return50: (price) => {
                    return price/2;
                },
                percent90: () => {

                },
                percent50: () => {

                }
            }
        }
        running(algorithm,price){
            let _obj = new strategy();
            return _obj.change[algorithm] && _obj.change[algorithm](price)
        }
    }

    return new strategy().running;
})();


console.log(PriceStrategy('return50','3214.32'))
上一篇 下一篇

猜你喜欢

热点阅读