19-js策略模式

var PriceStrategy = function() {
            var stragtegy = {
                return30: function(price) {
                    return +price + parseInt(price / 100) * 30;
                },
                return50: function(price) {
                    return +price + parseInt(price / 100) * 50
                },
                percent90: function(price) {
                    return price * 100 * 90 / 10000;
                },
                percent80: function(price) {
                    return price * 100 *80 / 10000;
                }
            }
            return function(algorithm, price) {
                return stragtegy[algorithm] && stragtegy[algorithm](price)
            }
       }();
       console.info(PriceStrategy('return50', 826));

 

posted @ 2017-10-19 17:21  RyanxChen  阅读(168)  评论(0编辑  收藏  举报