Regarding the nuance of the name onXXX, which is often used in event handlers, etc

Asked 1 years ago, Updated 1 years ago, 448 views

Speaking of event handlers, I have an image of onXXX, but I don't know what on means I'm not sure.

I'm worried about naming the method name of the function I'm currently creating, and I'm wondering if it's appropriate to use on, so I decided to ask you a question.
The callback-like method somehow makes me want to use onXXX, but I don't feel like callback = on.

technical-term

2023-04-18 15:02

1 Answers

on is often used in English nuances to indicate timing.
For example, onClick would mean "when clicked".
However, this is the name of the event, not the name of the feature.

For example, the GUI framework is centered on operations, so the name "when clicked" may be appropriate, but in a higher abstraction, it may be easier to understand what you want to do when clicked.
Even if the actual situation is the same, the appropriate name may vary depending on how you view it.

In the end, I can only say that it depends on the situation.
It is not categorized by clear rules.
If you have any habits in your language or field, you'd better follow them, and you should have some consistent rules in at least one project, but in general, there is no standard that you can say should be like this.


2023-04-18 15:37

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.