I study vanila JS, and try to optimize my code. I want to create a universal method that will read different settings and, depending on the incoming data launch another methods. I don’t really want to use with a lot of IF IF ELSE
What I got
Settings = {
SlideToShow: 2,
SlidetoScrolle: 2,
Scrollable: false
}
My "universal" method
_settingsReader(settings) {
for (const key in settings) {
if (Object.hasOwnProperty.call(settings, key)) {
this._set + key + (settings[key])
}
All problems hide here "this._set + key + (settings[key])". It doesn't call a method.
I just don't understand if something like this is possible. And how to implement it.
Metods that I want to launch
_setSlideToShow(param);
_setSlidetoScrolle(param);
_setScrollable(param);
I hope I was able to explain what I would like to see in the final result. I will be very happy if someone can help me with this problem.