0

据我所知,Spinelli 的 NoClickDelay JS 库无法“撤消”其功能。

例如:

var a = new NoClickDelay('body');
console.log(a)
//returns NoClickDelay

delete a;
console.log(a)
//still returns NoClickDelay

a = null;
//a is now empty, but NoClickDelay still exists

我知道我可以取消绑定onTouchStart,onTouchMoveonTouchEnd事件,但是如何new NoClickDelay()从内存和 DOM 中删除实例化的?

4

1 回答 1

1

尝试以下操作:

var Obj = {};
Obj.a = new NoClickDelay('body');
console.log(a);
delete Obj.a;
console.log(a);

小提琴:http: //jsfiddle.net/benno_007/euATH/1/

您不能删除变量。

删除 y; // 返回 false(删除不影响变量名)

来源:https ://developer.mozilla.org/en-US/docs/JavaScript/Reference/Operators/delete

编辑: 在删除事件监听器方面,尝试添加这个函数并运行它

function undoNoClickDelay(el) {
    if( window.Touch ) {
            el.removeEventListener('touchstart', this, false);
            el.removeEventListener('touchmove', this, false);
            el.removeEventListener('touchend', this, false);
            delete Obj.a;
    }
}
于 2013-02-05T04:09:45.540 回答