Mixing to Object example
CurlyBraceTT opened this issue · 3 comments
CurlyBraceTT commented
Got confused by example from the read-me. Initial code sample doesn't work and require some polishing. Passing this.events as a context will cause an error on this line:
event = this.events[event] = this.events[event] || []
ai commented
Hm. my output of this repl.it
:
node v9.7.1 linux/amd64
Repl.it: Installing fresh packages
Repl.it: nanoevents
+ nanoevents@1.0.2
added 1 package in 1.807s
Repl.it: package installation success
tick!
done
=> undefined
Everything seems fine. Could you provide error text in your case?
CurlyBraceTT commented
Its slightly modified example, not the original one - see commented lines and added emit
method.
Here is the expected original class usage:
https://repl.it/@CurlyBrace/nanoeventsmixing-original
And the input:
node v9.7.1 linux/amd64
Repl.it: Installing fresh packages
Repl.it: nanoevents
+ nanoevents@1.0.2
added 1 package in 1.178s
Repl.it: package installation success
TypeError: Cannot read property 'tick' of undefined
at on (/tmp/node_modules/nanoevents/index.js:62:45)
at Ticker.on (evalmachine.<anonymous>:8:28)
at evalmachine.<anonymous>:16:8
at Script.runInContext (vm.js:74:29)
at Object.runInContext (vm.js:182:6)
at evaluate (/run_dir/repl.js:137:14)
at Socket.<anonymous> (/run_dir/repl.js:120:5)
at Socket.emit (events.js:180:13)
at addChunk (_stream_readable.js:269:12)
at readableAddChunk (_stream_readable.js:256:11)
ai commented
You need to replace:
return this.emitter.on.apply(this.events, arguments)
to:
return this.emitter.on.apply(this.emitter, arguments)
this.events
→ this.emitter