Skip to content

Commit 118baeb

Browse files
authored
Update README.md
1 parent 5f6417b commit 118baeb

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

README.md

+21
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,24 @@ EventBus.addEventListener("custom_event", t1.doSomething, t1);
121121
t2.ready();
122122
```
123123

124+
## Example of usage EventBus.removeEventListener
125+
126+
To remove EventListener you have to pass same instance of callback
127+
```js
128+
129+
/* Wrong - callback functions are different instances */
130+
EventBus.addEventListener('EXAMPLE_EVENT', function() {
131+
console.log('example callback');
132+
});
133+
EventBus.removeEventListener('EXAMPLE_EVENT', function() {
134+
console.log('example callback');
135+
});
136+
137+
/* Correct - callback function is the same instance */
138+
EventBus.addEventListener('EXAMPLE_EVENT', function() {
139+
console.log('example callback');
140+
});
141+
EventBus.removeEventListener('EXAMPLE_EVENT', function() {
142+
console.log('example callback');
143+
});
144+
```

0 commit comments

Comments
 (0)