次の 4 つの匿名 jquery 関数を、パラメーターを渡す 1 つの関数に変換することはできますか?
これは私が持っているものです...
dropZone.addEventListener("dragenter", this.dragEnter, false);
dropZone.addEventListener("dragover", this.dragOver, false);
dropZone.addEventListener("dragleave", this.dragLeave, false);
dropZone.addEventListener("drop", this.dragDrop, false);
...
this.dragOver = function(ev) {
ev.stopPropagation();
ev.preventDefault();
this.className = "dragover";
}
this.dragLeave = function(ev) {
ev.stopPropagation();
ev.preventDefault();
this.className = "dragleave";
}
this.dragEnter = function(ev) {
ev.stopPropagation();
ev.preventDefault();
this.className = "dragenter";
}
this.dragDrop = function(ev) {
ev.stopPropagation();
ev.preventDefault();
this.className = "dragdrop";
}
機能的に似たものを探しています...
dropZone.addEventListener("dragenter", dropEvent(this,"dragenter"), false);
dropZone.addEventListener("dragover", dropEvent(this,"dragOver"), false);
dropZone.addEventListener("dragleave", dropEvent(this,"dragLeave"), false);
dropZone.addEventListener("drop", dropEvent(this,"dragDrop"), false);
...
function dragEvent(ev, label) {
ev.stopPropagation();
ev.preventDefault();
this.className = label;
}