Difference between Events and Functions?

前端 未结 3 1954
情深已故
情深已故 2021-01-05 03:42

I am new to Node, and I am struggling to understand the main difference between Events and Functions. Both need to be triggered, so why do we need an Event at all if we have

3条回答
  •  鱼传尺愫
    2021-01-05 04:31

    I suppose I see the biggest difference I see is that an event emitter could trigger multiple events that are listening, whereas just calling a function only triggers one thing.

    So for example, you could have numerous objects in a game that are all waiting for a step event that increments their animation.

    They are such a pain to debug though that I'd much rather just use functions.

提交回复
热议问题