My web page is designed for editing various types of products, each with different behaviors depending on their product type.
The variations in behavior include minor changes such as: a specific field being mandatory only for one product type, a dropdown list having fewer options for certain product types, an ajax call being made to a different URL, and more.
1/ I am looking for an elegant way to write JavaScript code that follows the open-closed principle and avoids using conditional statements like:
var idType = $('#idtype').val();
if (idType == 3)
2/ Can enums be utilized in JavaScript?
3/ Is there a particular design pattern that addresses this situation? The Strategy pattern seems like the closest fit.
4/ While these changes can currently be handled on the client-side using JavaScript, how should I approach modeling cases where the behavior differs between client-side and server-side?