Skip to content

Instantly share code, notes, and snippets.

@oakland
oakland / LazyMan.js
Last active February 17, 2017 07:37
// https://mp.weixin.qq.com/s?__biz=MzAxODE2MjM1MA==&mid=2651551620&idx=1&sn=509e8ff624cf676d35cb31315c87937e&chksm=8025a045b75229532293650e196403fc7558acb0b3e563bd87d21743371969ef97cc3d95b366&mpshare=1&scene=1&srcid=02158YYyKvXAJKAQTF0gdpHA&pass_ticket=HqKZKbs0BepJwfdcm3j3eBHYCepsXSrvyAfwKNyyo6o%3D#rd
// 最近一个面试题目很火,在网上找到一个答案,自己看了很多遍,对整个流程已经比较了解了,然后自己又简单修改了一下,记录下来。有想不懂的地方,大家可以打断点测试,了解整个过程是什么。
// LazyMan('Hank').sleep(3).eat('dinner'); 的过程是先执行所有的原型链上的方法,这个过程相当于把所有的 fn 都推入 tasks 这个数组之中,而 sleepFirst 则是放在最前面的。
// 然后再执行 setTimeout(function() {self.next()}, 0) 这个异步的函数,通过 next 这个函数的设计,一次次去执行 tasks 中所有的 fn。而所有的 fn 都是在执行之后再调用 next() 进而调用下一个 fn。
// setTimeout(function() {self.next()}, 0) 的设计非常巧妙,是开一个异步的进程,但是在所有的同步没有执行完毕之前,这个函数是不会执行的。所以肯定是所有的链式调用结束之后再开始self.next()。
// 整个这个设计还牵扯到很多技巧和概念,比如 闭包,数组的操作方法,setTimeout() 异步设计,原型链,链式调用,还有 fn && fn() 这个技巧等等。值得仔细研究。
// 这里面还有一个关于 setTimeout 的深入理解过程,参阅这篇文章: http://www.whohelpme.com/b/detail/121.html
function _LazyMan(name) {
this.tasks = [];
var self = this;
1. An operating system is a collection of software that manages hardware resources and provides an environment where applications run.
2. Linux Kernel + Apps = Distro
3. Linux Kernel is the layer that sits between the hardware and applications. Said in another way that it's the intermediary between software and hardware.
4. The most popular linux operating distributions are Red Hat Enterprise Linux and Ubuntu. CentOS is a RedHat Enterprise Linux derivitive that completely free.
5. PuTTY is a windows SSH client.
6. The command line utility ssh is used in Mac.
7. pwd - Displays the present working directory. cat - Concatenates and displays files. echo - Displays arguments to the screen. man - Displays the online manual. exit - Exits the shell or your current session. clear - Clears the screen.
8. Pointer 有点像快捷方式,比如一个文件夹的桌面快捷方式就是一个 pointer ,而这个 pointer 指向的是真正的文件夹的内容,有时候改变 pointer 和改变文件夹内容是两件事情。Pointer 还可以类必成 url 和真是的网页内容。
1. Linux 有点像一个城市的基础设置,而应用就好像是一个个的城市功能模块,比如学校、工厂、医院等。这些应用是运行在操作系统之上的,而操作系统是去控制基础资源的,电脑的这些基础资源就好像是一个城市的水、空气、土壤、植物等等。
2. Ubuntu, Debian, Red Hat Enterprise 等等这些,都是 linux 的不同版本而已。Ubuntu 一年发布两次,而 Debian 发行的版本很慢,但是非常稳定。