I’ve got something like this
var obj = new someClass(el, {
onOne: function () {
doThis();
},
onTwo: function () {
doThis();
},
onThree: function () {
doThis();
},
onFour: function () {
doThat();
}
});
So, the first three events will have the same result, only the fourth is different. Like this, it seems kind of repetitive, so I was hoping that I could do something like this
var obj = new someClass(el, {
onOne:
onTwo:
onThree: function () {
doThis();
},
onFour: function () {
doThat();
}
});
But I can’t.
I wonder, if there’s some way I can do something similar (without changing the class itself). In think it would make the code clearer and better maintainable.
How about predefining the function?
If you know keys of the object you may additionally try working with
forloop, for example