-
Sat 2021.03.27
@AndreyVS While searching for an answer to #1, our posts crossed:
Why can't I use this.emit(...)?
I'm now puzzled also, as:
ref: 'You cannot rebind this in an arrow function.'
violates ECMAScript specification:
https://stackoverflow.com/questions/33308121/can-you-bind-this-in-an-arrow-function
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions
It seems the L3()=>this.emit('TestEvent')
arrow function is bound to the setTiemout() object, or maybe this is bound to the application environment Global scope and not the L2 aClass.prototype.testEmit object as desired. This might explain why it just works, and not actually a specification violation.
Incidentatlly, Post #2 L1 should not terminate with a semi-colon, and L4 should.
Hi Everyone! On Puck I try to organize communication between objects with events (see Object.emit and discussion here). However, I cannot emit an event within a prototype function with 'this'. Thus if e.g. I have two step up modules, I cannot subscribe directly to each of them, and need to add either a module id as an event argument or additional empty object (see below).
In comments here is what I'd want:
Here is a way round with an empty object:
Why can't I use this.emit(...)?