1.介绍一下事件驱动编程---快餐店点餐。 在基于线程的方式中(thread-based way)你到了柜台前,把你的点餐单给收银员或者给收银员直接点餐,然后等在那直到你要的食物准备好给你。收银员不能接待下一个人,除非你拿到食物离开。想接待更多的客户,容易!加更多的收银员!当然,我们知道快餐店其实不是这样工作的。他们其实就是基于事件驱动方式,这样收银员更高效。只要你把点餐单给收银员,某个人已经开始准备你的食物,而同时收银员在进行收款,当你付完钱,你就站在一边而收银员已经开始接待下一个客户。在一些餐馆,甚至会给你一个号码,如果你的食物准备好了,就呼叫你的号码让你去柜台取。关键的一点是,你没有阻. Read More
posted @ 2013-08-22 01:41 等风来。。 Views(815) Comments(0) Diggs(0) Edit
//返回新对象,双方互不影响function clone(obj){ //alert('clone'); if(typeof(obj) != 'object') return obj; if(obj == null) return obj; //因为typeof(null) == object所以要加上这步 var newObj = {}; for(var i in obj){ newObj[i] = clone(obj[i]); //alert('obj['+i+'] '+obj[i]); } return newO... Read More
posted @ 2013-08-21 21:14 等风来。。 Views(181) Comments(0) Diggs(0) Edit
1.在js中所有要素都是继承自Object对象的,任何对象都能通过obj['name'] = something的形式来添加属性,相当于obj.name=something。之所以设计中括号这种存取方式是为了方便在存取属性不定的情况下把属性名作为变量传入进行存取。例如 function get(property){ return obj[property];}var name=get('name'); 2.var obj={name:"licous"};这个东西并不是大家所谓的json,而是声明一个对象。json是一种为了方便数据交换的有格式 Read More
posted @ 2013-08-21 21:05 等风来。。 Views(410) Comments(0) Diggs(0) Edit
1 2 3 4 5 js 6 103 104 105 106 107 Anchor 1108 Anchor 2109 Anchor 3110 111 112 113 Read More
posted @ 2013-08-21 15:05 等风来。。 Views(307) Comments(0) Diggs(0) Edit
1.注册可以直接调用f()中的b(),c(),d() .原因?自己想。 js //需要先点击这个,才能点击其他,否则出错 2.f()改为匿名函数----载入自执行 1 2 3 4 5 js 6 20 21 22 23 f()改为匿名函数,载入后自执行24 ... Read More
posted @ 2013-08-21 14:59 等风来。。 Views(279) Comments(0) Diggs(0) Edit
Scope Chain & Closure Example Scope Chain & Closure Example Anchor 1 Anchor 2 Anchor 3 2.应该改为: //使用onload事件,以前总是觉得自己不会犯这样的错,直到出错后才会真正记在头脑中。 Read More
posted @ 2013-08-21 14:19 等风来。。 Views(277) Comments(0) Diggs(0) Edit
1.forEach,map,filter三个函数者是相同的调用参数。(callback[, thisArg])callbackis invoked withthree arguments:theelement valuetheelement indexthearray being traversedif (!Array.prototype.forEach) { Array.prototype.forEach = function (fn, thisObj) { var scope = thisObj || window; for (var i = 0, j =... Read More
posted @ 2013-08-21 02:32 等风来。。 Views(257) Comments(0) Diggs(0) Edit
1.child_process是Node.js的一个十分重要的模块,通过它可以实现创建多进程,以利用多核计算资源。child_process模块提供了四个创建子进程的函数,分别是spawn,exec,execFile和fork。其中spawn是最原始的创建子进程的函数,其他三个都是对spawn不同程度的封装。spawn只能运行指定的程序,参数需要在列表中给出,相当于execvp系统函数,而exec可以直接运行复杂的命令。child_process.spawn(command, [args], [options])child_process.exec(command, [options], ca Read More
posted @ 2013-08-21 00:29 等风来。。 Views(3072) Comments(0) Diggs(1) Edit
1.process是一个全局进程,你可以直接通过process变量直接访问它。 process实现了EventEmitter接口,exit方法会在当进程退出的时候执行。因为进程退出之后将不再执行事件循环,所有只有那些没有回调函数的代码才会被执行。在下面例子中,setTimeout里面的语句是没有办法执行到的。1 process.on('exit', function () {2 setTimeout(function () {3 console.log('This will not run');4 }, 100);5 console.log('exit& Read More
posted @ 2013-08-21 00:07 等风来。。 Views(793) Comments(0) Diggs(0) Edit
1.今晚在在node.js的实验,在用socket.io.js时,发现html中有就改为了并把socket.io.js文件copy到目录下,启动服务后,console中出现unhandled socket.io url。一查,原来不用自己搞,服务端会自动生成的这个js文件。2.在浏览器中自动刷新显示当前server的时间 1 var app = require('http').createServer(handler); 2 var io = require('socket.io').listen(app); 3 var fs = require('fs Read More
posted @ 2013-08-20 00:55 等风来。。 Views(274) Comments(0) Diggs(0) Edit
------------------------------------------------------------------------------------------------------------ --------------- 欢迎联系 x.guan.ling@gmail.com--------------- ------------------------------------------------------------------------------------------------------------