What is meant by the term “hook” in programming?

前端 未结 12 2444
暖寄归人
暖寄归人 2020-12-07 06:56

I recently heard the term \"hook\" while talking to some people about a program I was writing. I\'m unsure exactly what this term implies although I inferred from the conve

相关标签:
12条回答
  • 2020-12-07 07:19

    hooks can be executed when some condition is encountered. e.g. some variable changes or some action is called or some event happens. hooks can enter in the process and change things or react upon changes.

    0 讨论(0)
  • 2020-12-07 07:19

    In the Drupal content management system, 'hook' has a relatively specific meaning. When an internal event occurs (like content creation or user login, for example), modules can respond to the event by implementing a special "hook" function. This is done via naming convention -- [your-plugin-name]_user_login() for the User Login event, for example.

    Because of this convention, the underlying events are referred to as "hooks" and appear with names like "hook_user_login" and "hook_user_authenticate()" in Drupal's API documentation.

    0 讨论(0)
  • 2020-12-07 07:20

    Hook denotes a place in the code where you dispatch an event of certain type, and if this event was registered before with a proper function to call back, then it would be handled by this registered function, otherwise nothing happens.

    0 讨论(0)
  • 2020-12-07 07:21

    Oftentimes hooking refers to Win32 message hooking or the Linux/OSX equivalents, but more generically hooking is simply notifying another object/window/program/etc that you want to be notified when a specified action happens. For instance: Having all windows on the system notify you as they are about to close.

    As a general rule, hooking is somewhat hazardous since doing it without understanding how it affects the system can lead to instability or at the very leas unexpected behaviour. It can also be VERY useful in certain circumstances, thought. For instance: FRAPS uses it to determine which windows it should show it's FPS counter on.

    0 讨论(0)
  • 2020-12-07 07:23

    Hooking in programming is a technique employing so-called hooks to make a chain of procedures as an event handler.

    0 讨论(0)
  • 2020-12-07 07:30

    Simple said:

    A hook is a means of executing custom code (function) either before, after, or instead of existing code. For example, a function may be written to "hook" into the login process in order to execute a Captcha function before continuing on to the normal login process.

    0 讨论(0)
提交回复
热议问题