Detailed javascript hook function

What is the hook function? (This is the system, you can not see this)

Hook function is part of the Windows message handling mechanism, the application can for all messages, event by setting the "hook" in the system-level filtering, message access under normal circumstances can not be accessed. Essence is defined by a hook used to program a processing system messages, system calls, and hung into the system. " From Baidu Encyclopedia "

Is not read, you're right, it was too official, and then put it more semantic:

Hook function when an event is triggered at the system level to capture him, and then do something. Program processing section for system messages, system messages for program processing, is that the hook function for processing system messages

  • It is a function, called by the system when the system is triggered messages
  • Not triggered by the user's own

What is the hook function? (Javascript in)

Before that you need to know about the callback function

The callback function is that you leave a processing method to the event, it will automatically execute you stay tune treatment after the incident

Hook function is like looking for a proxy to monitor whether the event occurred, if this proxy happened on the implementation of your event handler method; in this process, the agent is the hook function

  • In a sense, the callback function to do the process with the hook function in the same way as to call the tune
  • But one thing: the hook function is usually provided by the event's occurrence. Straightforward to say, it leaves a hook, the hook is hooked to the role of your callback method
⬇⬇ I still do not understand ⬇⬇

I bluntly said:

Hook function is a callback function.
Hook function is called in general is a framework inside, this framework is a callback function triggered at some stages of the life cycle.

If you understand React and Vue, there are life-cycle function, that is a page of function execution of different periods, those are the hook function

Code shows: (vue framework)

<div id="#root"></div>

    <script>
    
        new Vue({  //new 一个实例对象
            el:"#root",
            data:{
                str:1,
            },
            mounted(){    //当我的实例挂载完毕之后 会执行  这个就是钩子函数
                console.log(123)
            }
        })

    </script>

Focus:
The mounted () I did not write, I just use the vue.js this framework, which comes with it, whether I write do not write it in there, but when I call it later, it will execute my parameters Content

发布了63 篇原创文章 · 获赞 6 · 访问量 1219

Guess you like

Origin blog.csdn.net/qq_44163269/article/details/105123407