Cannot call method 'addEventListener' of null原因很简单,JavaScript代码中要引用到DOM对象,但是这个DOM对象在JavaScript执行后才会出现,现在无法找到,所以才会出现如上提示。这个问题给我们的警示是:要了解JavaScript的阻塞问题,浏览器渲染内容的原理最好了解一些;getElementById的时候一定要保证Dom对象存在,否则就会出现问题。解决的办法是:把JavaScript代码放在引用DOM后面。 Read More
posted @ 2013-08-24 21:47 等风来。。 Views(3661) Comments(0) Diggs(0) Edit
1.BLOCKING THE EVENT LOOP Node and JavaScript runtimes in general are single-threaded event loops. On each loop, the runtimeprocesses the next event in queue by calling the associated callback function. When that eventis done, the event loop fetches and processes the next event; this pattern contin. Read More
posted @ 2013-08-24 16:15 等风来。。 Views(271) Comments(0) Diggs(0) Edit
Let’s say you want a function that does some I/O — such as parsing a log fi le — that will periodicallybe executed. Let’s give that function the generic name my_async_function. You could start byusing setInterval like this:var interval = 1000;setInterval(function() { my_async_function(function() ... Read More
posted @ 2013-08-24 16:08 等风来。。 Views(491) Comments(0) Diggs(0) Edit
1.RegExp对象:五个属性二个方法五个属性:global, ignoreCase,multiline,lastIndex,source二个方法:exec()--模式匹配test()--检测一个字符串是否含有某个模式2.例子var pattern = /\bJava\w*\b/g;var text = 'JavaScript is more fun than Java or JavaBeans!';var result;while((result = pattern.exec(text)) != null){ console.log('Matched! '+r Read More
posted @ 2013-08-24 03:44 等风来。。 Views(229) Comments(0) Diggs(0) Edit
括号用来将子表达式标记起来,以区别于其他表达式比如很多的命令行程序都提供帮助命令,键入 h 和键入 help 的意义是一样的,那么就会有这样的表达式: h(elp)?字符h之后的elp可有可无这里的括号仅仅为了将 elp 自表达式与整个表达是隔离(因为 h 是必选的)。括号用来分组,当正则表达式执行完成之后,与之匹配的文本将会按照规则填入各个分组比如,某个数据库的主键是这样的格式:四个字符表示省份,然后是四个数字表示区号,然后是两位字符表示区县,如 yunn0871cg 表示云南省昆明市呈贡县,我们关心的是区号和区县的两位字符代码,怎么分离出来呢? var pattern = /\w{4... Read More
posted @ 2013-08-24 03:23 等风来。。 Views(1016) Comments(0) Diggs(0) Edit
1 var fs = require('fs'); 2 3 /*cross device link 4 fs.rename('c:\\err.LOG','d:\\err.LOG',function(err){ 5 console.log(err.code); 6 }); 7 */ 8 9 move('c:\\err.LOG','d:\\err.LOG',function(err){10 if(err) throw err;11 });12 13 14 function move(oldpath,newpath,ca Read More
posted @ 2013-08-24 00:07 等风来。。 Views(605) Comments(0) Diggs(0) Edit
一。目录➤ Understanding why you need buffers in Node➤ Creating a buffer from a string➤ Converting a buffer to a string➤ Manipulating the bytes in a buffer... Read More
posted @ 2013-08-23 23:38 等风来。。 Views(708) Comments(0) Diggs(0) Edit
1.屏幕坐标:相对于桌面左上角 窗口坐标:相对于窗口的左上角 文档坐标:相对于html文档左上角当有滚动条时,窗口坐标与文档坐标之间有区别 Read More
posted @ 2013-08-23 01:50 等风来。。 Views(181) Comments(0) Diggs(0) Edit
1.两个阶段三个模型:Netscape支持事件捕获,IE支持事件冒泡,w3c是先捕获后冒泡 Event Flow Event Flow List 1 List 2 List 3 ... Read More
posted @ 2013-08-23 00:21 等风来。。 Views(292) Comments(0) Diggs(0) Edit
哈哈。。写了一个钟,一点一点加功能。 1 function Publisher(){ 2 this.subscribers = []; //存储订阅者 3 this.news = []; //存储要发布的消息 4 } 5 //使用“推”方式:由publisher推消息给Subscribers 6 7 8 Publisher.prototype = { 9 deliver : function(data){ 10 var that = this;11 this.subscribers.forEach(function(){12 ... Read More
posted @ 2013-08-22 16:44 等风来。。 Views(239) Comments(0) Diggs(0) Edit
------------------------------------------------------------------------------------------------------------ --------------- 欢迎联系 x.guan.ling@gmail.com--------------- ------------------------------------------------------------------------------------------------------------