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

Javascript设计模式之策略模式 #62

Open
pengjielee opened this issue Oct 31, 2019 · 0 comments
Open

Javascript设计模式之策略模式 #62

pengjielee opened this issue Oct 31, 2019 · 0 comments

Comments

@pengjielee
Copy link
Owner

策略模式:定义一系列的算法,把它们一个个封装起来,并且使它们可以相互替换。

var strategies = {
	'A': function(salay){
		return salay * 6;
	},
	'B': function(salay){
		return salay * 4;
	},
	'C': function(salay){
		return salay * 3;
	},
	'D': function(salay){
		return salay * 2;
	}
}

var calculateBouns = function(level,salary){
	return strategies[level](salary);
}

console.log(calculateBouns('A',20000))
console.log(calculateBouns('B',20000))
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