Skip to content
New issue

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

allOff删除某个没有添加过的事件将会删除所有的事件 #4

Open
KaiOrange opened this issue Mar 27, 2018 · 2 comments
Open

Comments

@KaiOrange
Copy link

个人觉得下面这样好一些:

proto.allOff = function(eventName) {
        if (eventName) {
            this.__events[eventName] = []
        } else {
            this.__events = {}
        }
    };
@mqyqingfeng
Copy link
Owner

@KaiOrange 恩恩,确实有这个问题,感谢指出~ 要不要发起一个 PR ?

@mqyqingfeng
Copy link
Owner

@KaiOrange 不过这样的话,当删除一个不存在的事件时,比如 'test' 事件时,我们就会设置 __events.test = [],这个又是没有必要的,所以可以写成:

proto.allOff = function(eventName) {
        if (eventName) {
            if (this.__events[eventName]) this.__events[eventName] = []
        } else {
            this.__events = {}
        }
    };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants