node.js Taiwan 2012/03/16

11
node.js Taiwan 2012/03/16

description

 

Transcript of node.js Taiwan 2012/03/16

Page 1: node.js Taiwan 2012/03/16

node.js Taiwan

2012/03/16

Page 2: node.js Taiwan 2012/03/16

CoffeeScript

• JavaScript: The Good Parts:

• “JavaScript是披了C的衣服的Lisp”

• CoffeeScript讓JS寫起來更簡潔

Page 3: node.js Taiwan 2012/03/16

Foreach

• JavaScript (ES5) 有forEach

• Underscore.js 有 each / forEach ,效果完全相同

• 簡單安全

Page 4: node.js Taiwan 2012/03/16

Foreach

var array = [1, 2, 3]

for (var i = 0; i <= array.length; i++) {

var item = array[i];

alert(item);

}

JS for loop

Oops.

Page 5: node.js Taiwan 2012/03/16

Foreach (coffee)

for num in [1, 2, 3]

alert num

Page 6: node.js Taiwan 2012/03/16

Foreach (js)

_.each([1, 2, 3], function(num){ alert(num); });

underscore.js

_.each([1, 2, 3], alert);

效果也相同

[1, 2, 3].forEach(alert);

Array.prototype.forEach (ES5)

Page 7: node.js Taiwan 2012/03/16

ES5-shim

• 古早瀏覽器的救星

• https://github.com/kriskowal/es5-shim

• 延伸閱讀

• http://www.modernizr.com/

Page 8: node.js Taiwan 2012/03/16

Variable Scope (coffee)

sys = require 'sys'

foo = 42

(() -> foo = 43)()

sys.puts foo # 43

sys = require 'sys‘

my = (local) -> local()

foo = 42

my (foo) -> foo = 43

sys.puts foo # 42

https://github.com/jashkenas/coffee-script/issues/712

Page 9: node.js Taiwan 2012/03/16

Form middleware

• https://github.com/guileen/node-iform

• Express寫起來會更簡潔

Page 10: node.js Taiwan 2012/03/16

CoffeeScript in the Wild

• Hubot by GitHub

• http://hubot.github.com/

• Spine (client-side MVC)

• http://spinejs.com/