The hook mechanism is like this, you write a method according to a rule (this rule is on the method name), and then the page is loaded before the unified execution of all the hooks function.
Note the Callhooks method, where the local variable s is the name of the hook function must have content. -This is the way to use hooks!
The object that handles the hook is var hook = (function () {return {timer:null, init:function () {This.callhoo KS (' init '); }, Callhooks:function (init) {var s = "Hook_" + init + ' _event ', f = []; for (Var h in window) {if (H.indexof (s)! = 0) Continue; F.push (h); } this.hookstimeout (f); }, Hookstimeout:function (hooks) {if (0 = = = hooks.length) {if (This.timer) cleartime Out (This.timer); Return } var h = Hooks.shift (); Window[h].apply (); WINDOW[H] = undefined; Window.settimeout (This.hookstimeout (hooks), 200); } } }()); Hook 1 var hook_init_event_tpl_html = function () {document.getElementById (' Test '). InnerHTML = ' This is html! '; }//Hook 2 var hook_init_event_tpl_console = function () {Console.Log (' This is console! '); }//preferably before the page is finished loading, that is, before Window.onload () Hook.init ();
Summarize
Many problems, if we discuss together is very helpful, in the process we can learn a lot of things, we can also in the process from the cattle to school to many ways and thinking process, almost every technical seminar I have a lot of good harvest-I do not know if this is the legendary "brainstorming."