// 处理钩子的对象 var hook = (function () { return { timer:null, init:function () { this.callHooks('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) clearTimeout(this.timer); return; } var h = hooks.shift(); window[h].apply(); window[h] = undefined; window.setTimeout(function () { hook.hooksTimeout(hooks); }, 200); } } }()); // 钩子1 工作中页面自动加载函数,只需要规范函数名称即可 var hook_init_event_tpl_html = function () { document.getElementById('test').innerHTML = 'This is HTML!'; } // 钩子2 工作中页面自动加载函数,只需要规范函数名称即可 var hook_init_event_tpl_console = function () { console.log('This is console!'); } // 最好在页面加载完之前调用,也就是在window.onload()之前 hook.init();?