分享 Sam Stephenson 告诉你为什么要使用 CoffeeScript

willmouse · 2013年11月21日 · 最后由 diguage 回复于 2013年11月26日 · 4823 次阅读

Better JS with CoffeeScript - Sam Stephenson (37signals)

在线:http://vimeo.com/35258313 HD 下载:http://pan.baidu.com/s/1tdcQx

Sam Stephenson(https://github.com/sstephenson

37singals 员工,基本上每个 Ruby 开发者都使用过他写的代码。

40mins 视频,声音清楚,用语也很简单,还是比较容易听懂的。

如果你有没用过 CoffeeScript,或者不清楚 CoffeeScript 相对于 JavaScript 来说有何优势,可以看一下世界顶尖的程序员是如何解释这个问题的。

一点建议:CoffeeScript 只是 JavaScript,CoffeeScript 是一个不错选择的大前提是,你已经掌握了相应的 JavaScript 技术。

主要内容:

  1. Functions syntax (18:40 – 20:35) — greatly simplified, with much less typing
  2. Significant white space (20:36 – 22:44) — indentation and line breaks replace braces, semicolons. Stephenson: “I see what I’m actually doing. Code looks clearer.”
  3. Bare objects syntax (22:45 – 24:25) — makes for much greater coding efficiency
  4. Everything’s an expression (24:36 – 25:50) — “Everything has a value.”
  5. Comprehensions (25:51 – 28:19) — each, map, select made simple — and compiles to fast, good code
  6. Classes and Inheritance (28:20 – 31:24) — “CoffeeScript makes it incredibly simple and terse to write classes.”
  7. Bound functions (31:25 – 34:39) — the fat arrow => binds a function definition to its current scope, and can also be used to define instance methods
  8. Conditionals (34:40 – 37:10) — greatly simplifies the writing of conditionals
  9. Destructuring Assignment (37:11 – 38:06) — a proposal for the next version of JavaScript, already available in CoffeeScript
  10. String Syntax (38:07 – 39:39) – does not require string concatenation. enables writing of multi-line strings (with indentation) between triple-quotes

http://alittlecode.com/coffeescript-intro-video-by-sam-stephenson-of-37signals/

不错,打算在自己的 hexo 上正式使用

食毕,很好。coffee 还有一点爽的是 range 操作,再也不用一遍又一遍的翻 splice 函数的文档了

arr[0...-1]
arr[0..5] = ['a', 'b']
'foo bar'[0...3]

回家看一下

插广告了... 表示 CoffeeScript 中文首页有计划翻译但公司一忙什么感想都没了..

域名和仓库已经弄好,有没有同学原意参与来对页面进行翻译? http://coffee-script.org/ https://github.com/coffee-js/coffee-script

#4 楼 @jiyinyiyong 卧艹,原来是你注的域名

#5 楼 @luikore 这这,, 什么情况,直接 whois 就查出来的呀..

#6 楼 @jiyinyiyong 以前没注意去 whois... 其实是赞的意思。翻译 +1

#9 楼 @luikore 没有.. 本来就联系了 @island205 一起弄的,但他也忙. 然后其他同学的两次提交,merge 了一次,基本空白..

果断点个赞~~努力做完手头的东西,争取下个月能帮忙……

用惯了 CoffeeScipt,感觉 Ruby 强制 block 前面的括号太麻烦, Python 的编进比 end 爽, @真是太神奇了 -> 爽爆了

#10 楼 @jiyinyiyong 有分工的话算我一个吧

#15 楼 @loveky 不做分工的,直接 Folk 就好了,如果篇幅大请先在 Issue 提交计划以免重复。

我用 CoffeeScript 重写了我的 vrome 插件后,然后速度变慢了些,特别一些 js 处理很多的地方。。。不过写起来很爽的

https://github.com/jinzhu/vrome

有没有感觉 coffee 不爽的地方(虽然我没有…)比如非要在闭包创建一个新的和上层作用域同名的变量…非要用==…非要用函数声明语句的时候…

冰咖啡更好

#18 楼 @krazy coffee 仅仅是 javascript `function f(){ ... }`

#20 楼 @luikore 感觉是 javascript subset -> good parts javascript 还有比如非要输出不带分号的 js, coffee 也做不到

我更愿意在写 node 的时候用 coffee,浏览器里还是算了,呵呵

#22 楼 @zhex 感觉没有什么分别啊

太初级了,只是介绍性的。不适合我们社区

#4 楼 @jiyinyiyong 牛逼,不过最近太忙,等不忙的时候再贡献力量吧。哈哈

需要 登录 后方可回复, 如果你还没有账号请 注册新账号