事件处理程序和函数是同一件事吗?

发布于 2024-10-07 21:44:12 字数 84 浏览 0 评论 0原文

根据我的理解,与函数不同,事件处理程序接收事件对象作为参数。

这两个词之间还有其他区别还是相似?

谁能详细说明这两个术语?

As per my understanding, unlike functions, event handler receives the event object as parameter.

Is there any other difference between those two words or both are similar?

Can anyone elaborate both the terms?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

妄司 2024-10-14 21:44:12

这实际上取决于您使用的特定语言和 API。例如,在 C 语言中,事件处理程序通常作为函数实现。在 C++ 中,它们也可以是可调用对象。其他语言可能提供不同的选项。

It really depends on the specific language and API you are using. In C for instance, event-handlers are usually implemented as functions. in C++ they can also be callable objects. Other languages may offer different options.

柏拉图鍀咏恒 2024-10-14 21:44:12

这可能取决于语言。事件处理程序是一个通常具有特殊参数(在大多数情况下)的函数,其中该参数是事件对象。

所以不,事件处理程序和函数之间实际上没有区别。您可以像调用函数一样轻松地调用事件处理程序,只是您必须将一些事件对象传递给事件处理程序函数,但情况并非总是如此。

基本上,您永远不会像调用函数那样调用事件处理程序,当触发某些内容时,您会调用事件,这可能是唯一的区别。

我希望这篇文章对您有所帮助。

It may depend on the language. Event handler is a function which often has a special parameter (in most cases) where the parameter is the event object.

So no, there's really no difference between an event handler and a function. You could easily call an event handler just as you would call a function, except you would have to pass some event object to the event handler function, which is not always the case.

Basically you would never call an event handler as you would call a function, you would have something invoke the event when something is triggered, that may be the only difference.

I hope this post is helpful.

很酷不放纵 2024-10-14 21:44:12

嗯,事件处理程序特定于您使用的框架。 Java 的 GUI 模型基于偶数处理程序,通常您将实现预期接口(如 KeyListener)的匿名内部类传递给 addKeyListener(或类似)方法。

在 C 中,通常使用函数指针来达到相同的效果。按钮结构将保存指向回调的函数指针,并且可以向该函数传递事件结构。

C++ 允许您使用函数指针的想法,或者您可以定义一个对象,当您尝试“调用”它时运行某个方法 - 适当定义的对象上的 some_obj() 会调用某个函数您的选择。你甚至可以让它接受争论。 Python也是这样的。

如果回调采用指定事件的参数,则它通常称为事件处理程序。但它们几乎可以互换使用。

Well, event handlers are specific to the framework you use. Java's GUI model is based on even handlers, typically you pass an anonymous inner class that implements the expected interface (like KeyListener) to the addKeyListener (or similar) method.

In C, you typically use function pointers to the same effect. A button struct would hold a function pointer to a callback, and this function could be passed an event struct.

C++ allows you to use the function-pointer idea, or you can define an object that runs some method when you try to 'call' it - some_obj() on a suitably-defined object would call some function of your choice. You could even make it take arguments. Python is like this as well.

If a callback takes a parameter that specifies the event, it's typically called an event handler. But they can be used pretty much interchangeably.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文