去看一些语言的官方文档的时候总会提到的“钩子”其实是什么?

前端小白,写代码的时候,经常要看文档API,今天去看Webpack文档的时候又再次遇到了钩子这个词,发现很多时候都会提到这个名词,另外还有,钩子函数注入钩子,诸如此类,你们说钩子其实是在说什么?小白一枚,烦赐教~

阅读 1.9k
2 个回答

钩子其实就是一个函数,当你写了对应的函数的时候,框架会在特定的情况下调用你的函数,如启动,更新,完成等。。。

In computer programming, the term hooking covers a range of techniques used to alter or augment the behavior of an operating system, of applications, or of other software components by intercepting function calls or messages or events passed between software components. Code that handles such intercepted function calls, events or messages is called a hook.
维基百科

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题