Help with understanding syntax regarding Events

Fairly new to javascript/typescript. I find the syntax understandable but there’s one thing that i’m trying to wrap my head around atm.

Consider the following code:

A. this.node.on("touchstart", function (){....}, this);
B. this.node.on("touchstart", function (){....}, this.node);

Am I right to assume that in A, the “touchstart” event is registered to the script. And in B, the event is registered to the node element of the object this script is attached to.

If this is the case, when would you use B (I’m using A all the time atm).

In most case, I used B.
because the event bubbles and event system, unregistered event, etc, all that is based CCNode.
so I strongly suggest you use B better than A

1 Like