####node api exercise
Created
December 15, 2011 02:17
-
-
Save jackywyz/1479535 to your computer and use it in GitHub Desktop.
coffeescript+nodejs复习
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
***********************JS原型 | |
1. js 中 apply 和 call 区别是必须apply(someobj,[a,b]),call(someobj,a,b) | |
1. 函数P.prototype,对象有new P().__proto__=P.prototype的原型链 | |
p.__proto__.constructor ==Person | |
{}.prototype.constructor=={} | |
Object.prototype.constructor==Object | |
a.prototype.constructor==a | |
2. 每个对象都有函数constructor和__proto__(Object对象没有) | |
3. 每个constructor中都有prototype属性和__proto__属性. | |
4. with(m=Math) max(1,2) | |
5. if(n=1e5)alert(n), ’1e5‘为科学计数法 | |
*********************闭包 | |
1. 闭包就是能够读取其他函数内部变量的函数 | |
2. 定义在一个函数内部的函数 | |
3. 实现封装(function(){var name = 'jack'; return{getName:name}})() | |
4. 匿名自执行函数 (function(name){})('jack') | |
5. 缓存数据 (function(){var cache={}; return {getCache:function(){if('a' in cache){return cache['a']}})(); | |
******************关键字: | |
do -> "hello" 执行后面的函数(closure闭包) | |
when | |
while ,loop(while true),until(while false) | |
switch | |
if then else | |
for in(js for var;语法) / for of (js for in 语法) | |
*******************coffee闭包: | |
do ($, window) -> | |
$ -> | |
alert "js!" | |
#####next one demo | |
do (win) -> | |
(e)-> | |
console.log e | |
******************数据结构: | |
[] 列表数组 | |
{} map结合,对象 | |
number | |
string | |
null | |
undefined | |
Boolean | |
******************函数: | |
fun = (x=2)->x+2 | |
#splate: | |
* race = (a, b...) -> alert b. `race 1,2,3` | |
******************上下文,范围, 原型 | |
age = 32 | |
Ob = -> | |
@name = 2 | |
@age=25 | |
******************类 | |
class Test | |
@age:25 # 类级别属性,Test.age = 25 | |
constructor:(@name)-> #构造函数,没有返回值 | |
alert @name | |
move:->2 | |
super() 父类构造器 | |
******************对象 | |
obj = name:'jack',age:2,键值对 | |
obj = {a:1,b:2} | |
obj = | |
move:-> | |
age:25 | |
* 调用,obj.name,obj['name'] | |
******************表达式 | |
if 2>1 then 2 else 3 同ruby,haskell | |
for i in [1,2] | |
for k,v of {1:2,2:3} | |
## Comprehensions | |
a = (i for i in [1..10] by 2 when i >2 ) #此处的when是filter条件 | |
#插值: | |
quote = "A picture is a fact. -- #{ author }" | |
## case | |
switch i | |
when 2 then alert 2 | |
when 3 then alert 3 | |
else | |
## catch | |
try | |
a = b | |
catch error | |
alert error | |
finally | |
## | |
unlesss a 是if的反转 | |
a = 2 unless 2>3 | |
##with语句 | |
scope = (obj,f)-> | |
f.call obj | |
scope Math,-> | |
alert(@max 1,2) | |
******************操作符 | |
? 判断bool值,b?=2, fun?().say, fun?.get() | |
is | |
isnt | |
not | |
and | |
or | |
true, yes, on | |
false, no, off | |
@, 同 this | |
of 同 in | |
in 是否在list列表中 | |
-> 函数 | |
=> 绑定,在函数外套一层_bind(->,this) | |
:: 原型方法定义 | |
.. range化 | |
... splat ,列表数组参数化 | |
******************模块 | |
require('./mytest'); | |
global ? window | |
#导出 | |
module.exports = User | |
exports.say=say |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment