Reputation: 161
I'm using jQuery UI droppable
and draggable
. Based on what element was dropped on some canvas different functions are invoked. So right now it's something like this:
$('#myCanvas').droppable({
drop: function (e, ui) {
if (draggableId === "idA") {
functionA();
} else if (draggableId === "idB") {
functionB();
} else if (draggableId === "idC") {
functionC();
}
}
});
I wanna get rid of that ugly complexions. It looks like a polymorphism problem, but I don't really know how to handle this in such a case. Thanks for help!
Upvotes: 0
Views: 53
Reputation: 388316
Try
var fns = {
idA: functionA,
idB: functionB,
idC: functionC
}
$('#myCanvas').droppable({
drop: function (e, ui) {
var fn = fns[draggableId];
if($.isFunction(fn)){
fn();
}
}
});
Upvotes: 1