惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
Help Net Security
Help Net Security
P
Privacy International News Feed
T
Threat Research - Cisco Blogs
C
Cisco Blogs
C
CERT Recently Published Vulnerability Notes
NISL@THU
NISL@THU
L
LINUX DO - 热门话题
Security Latest
Security Latest
A
Arctic Wolf
G
GRAHAM CLULEY
月光博客
月光博客
S
Securelist
D
Docker
J
Java Code Geeks
T
Troy Hunt's Blog
T
Tenable Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
SecWiki News
SecWiki News
S
Security @ Cisco Blogs
量子位
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
L
LINUX DO - 最新话题
Recent Commits to openclaw:main
Recent Commits to openclaw:main
aimingoo的专栏
aimingoo的专栏
博客园 - 【当耐特】
H
Heimdal Security Blog
The Hacker News
The Hacker News
博客园 - 三生石上(FineUI控件)
Application and Cybersecurity Blog
Application and Cybersecurity Blog
N
Netflix TechBlog - Medium
Vercel News
Vercel News
Forbes - Security
Forbes - Security
B
Blog RSS Feed
H
Hackread – Cybersecurity News, Data Breaches, AI and More
IT之家
IT之家
B
Blog
MongoDB | Blog
MongoDB | Blog
博客园 - 聂微东
Google DeepMind News
Google DeepMind News
S
Secure Thoughts
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Check Point Blog
云风的 BLOG
云风的 BLOG
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
T
The Blog of Author Tim Ferriss
L
Lohrmann on Cybersecurity
F
Full Disclosure
D
Darknet – Hacking Tools, Hacker News & Cyber Security
P
Proofpoint News Feed

博客园 - 深蓝--广州

AngularJs angular.identity和angular.noop详解 css中clearfix清除浮动的用法及其原理示例介绍 opacity与RGBA透明的区别 CSS3 Gradient javascript语言精粹 严格模式认识 Promise与Defer认识 使用javascript打开一个新页而不被浏览器屏蔽 关于浏览器缓存 ie6下js更新元素display:block后,仍然不显示的hack办法 jQuery jsonp无法捕获404、500状态错误 移动端开发问题整理 修改input的type属性 transform:rotate在手机上显示有锯齿的解决方案 jQuery.validate 常用方法及注意问题 SWFObject推出2使用示例 .NET种Json时对单引号和特殊字符串的处理 自定义枚举类型注释属性,并在程序中获取 Python Win32 Extensions
javascript钩子机制
深蓝--广州 · 2014-08-19 · via 博客园 - 深蓝--广州

钩子机制是这样的,大家按照某一规则写一个方法(这个规则在方法名称上),然后页面加载完之前,统一执行所有的钩子函数。

注意callHooks方法,里面的局部变量s就是钩子函数名称中一定要有的内容。——这是使用钩子的方法!

// 处理钩子的对象  
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(this.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(); 

总结

很多问题,如果大家一起讨论是很有帮助的,在这过程中我们能学到很多东西,我们也可以在这过程中从牛人身上学到很多方法和思维过程,几乎每次的技术讨论会我都有不菲的收获——我不知道这是不是传说中的“头脑风暴”。