Skip to content

策略模式

59 字小于 1 分钟

js设计模式

2024-12-28

let strategy = {
 S:(salary) => {
  return salary*5
 },
 A:(salary) => {
  return salary*4
 },
 B:(salary) => {
  return salary*3
 },
 C:(salary) => {
  return salary*2
 },
}
function settlement(grade,salary){
 return strategy[grade](salary)
}
settlement('S',10000)  // 50000
settlement('A',5000) // 20000