Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

策略模式 #11

Open
txw2018 opened this issue May 7, 2020 · 0 comments
Open

策略模式 #11

txw2018 opened this issue May 7, 2020 · 0 comments

Comments

@txw2018
Copy link
Owner

txw2018 commented May 7, 2020

定义:指对象有某个行为,但是在不同的场景中,该行为有不同的实现算法

const activityObj = {
  special(price){
     return price * 0.6
  },
  secondsKill(price){
    return  price * 0.5
  },
  activity(price){
    return  price * 0.9
  }
}

const askPrice =function(type,money) {
  return activityObj[type](money);
};

console.log(askPrice('special',10000)); // 6000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant