javascript - To override the weight of a field in items with different IDs, is there a more elegant and easy-to-maintain way besides directly using the if else statement?
巴扎黑
巴扎黑 2017-07-05 10:51:39
0
1
728

There is a batch of products, all of which contain a config field. Now there are products with different IDs in a list, and the required config field needs to be taken out according to certain weight rules:
For example, the id is 1, The weight of 3 is higher than 2 and 4, and the weight of id 2 and 4 is higher than 5 and 7
So how can we design the code other than simply using if-else to operate? So that it is easier to maintain

巴扎黑
巴扎黑

reply all(1)
仅有的幸福

switch? It’s better to encapsulate it into a function
if else is also ok, it’s not complicated

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template