Cannot call method 'addEventListener' of null原因很简单,JavaScript代码中要引用到DOM对象,但是这个DOM对象在JavaScript执行后才会出现,现在无法找到,所以才会出现如上提示。这个问题给我们的警示是:要了解JavaScript的阻塞问题,浏览器渲染内容的原理最好了解一些;getElementById的时候一定要保证Dom对象存在,否则就会出现问题。解决的办法是:把JavaScript代码放在引用DOM后面。 Read More
posted @ 2013-08-24 21:47 等风来。。 Views(3665) 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(493) 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(1022) 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(611) Comments(0) Diggs(0) Edit
------------------------------------------------------------------------------------------------------------ --------------- 欢迎联系 x.guan.ling@gmail.com--------------- ------------------------------------------------------------------------------------------------------------