We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
您好,我发现那个indexOf有点问题,不能避免重复添加事件
indexOf
function indexOf(array, item) { if (array.indexOf) { return array.indexOf(item); } else { var result = -1; for (var i = 0, len = array.length; i < len; i++) { if (array[i] === item) { result = i; break; } } return result; } }
在添加事件的时候,使用indexOf(listeners, listener) === -1判断listeners没有listener才添加,但是listener可能为object,也可能为function,所以我修改为以下
indexOf(listeners, listener) === -1
listeners
listener
object
function
function indexOf (array, item) { var result = -1 item = typeof item === 'object' ? item.listener : item for (var i = 0, len = array.length; i < len; i++) { if (array[i].listener === item) { result = i break } } return result }
不知道分析的对不对?
The text was updated successfully, but these errors were encountered:
@xxxgitone 啊,确实有问题,感谢指出~ o( ̄▽ ̄)d 欢迎发起一个 Pull requrest ,我会 merge 的~
Sorry, something went wrong.
No branches or pull requests
您好,我发现那个
indexOf
有点问题,不能避免重复添加事件在添加事件的时候,使用
indexOf(listeners, listener) === -1
判断listeners
没有listener
才添加,但是listener
可能为object
,也可能为function
,所以我修改为以下不知道分析的对不对?
The text was updated successfully, but these errors were encountered: