node.js Taiwan 2012/03/16
-
Upload
minamo-ph -
Category
Technology
-
view
974 -
download
2
description
Transcript of node.js Taiwan 2012/03/16
node.js Taiwan
2012/03/16
CoffeeScript
• JavaScript: The Good Parts:
• “JavaScript是披了C的衣服的Lisp”
• CoffeeScript讓JS寫起來更簡潔
Foreach
• JavaScript (ES5) 有forEach
• Underscore.js 有 each / forEach ,效果完全相同
• 簡單安全
Foreach
var array = [1, 2, 3]
for (var i = 0; i <= array.length; i++) {
var item = array[i];
alert(item);
}
JS for loop
Oops.
Foreach (coffee)
for num in [1, 2, 3]
alert num
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)
ES5-shim
• 古早瀏覽器的救星
• https://github.com/kriskowal/es5-shim
• 延伸閱讀
• http://www.modernizr.com/
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
Form middleware
• https://github.com/guileen/node-iform
• Express寫起來會更簡潔
CoffeeScript in the Wild
• Hubot by GitHub
• http://hubot.github.com/
• Spine (client-side MVC)
• http://spinejs.com/
Node.js 台灣社群協作電子書
• http://book.nodejs.tw/
• https://github.com/nodejs-tw/nodejs-wiki-book
• 製作自己的電子書!
• http://contpub.org/read/nodejs-wiki-book
• reStructuredText
• http://docutils.sourceforge.net/rst.html