diff --git a/snippets/createEventHub.md b/snippets/createEventHub.md index 65690fa92..66c718bc7 100644 --- a/snippets/createEventHub.md +++ b/snippets/createEventHub.md @@ -21,7 +21,7 @@ const createEventHub = () => ({ this.hub[event].push(handler); }, off(event, handler) { - const i = this.hub[event].findIndex(h => h === handler); + const i = (this.hub[event] || []).findIndex(h => h === handler); if (i > -1) this.hub[event].splice(i, 1); } });