Coco 0.7.3
https://github.com/satyr/coco/tree/0.7.3
0.6.2 | 0.7.3 |
---|---|
-> ...; void |
!-> ... |
x = !x |
!=x |
[+a, +b] |
+[a, b] |
(exports ? this).x = x |
export x |
a = b = void |
var a, b |
_ = f!; _ = g _; _.m! |
f! => g _ => _.m! |
a <<< b if a? |
a? <<< b |
{p: [q]:p} = o |
{[q]:p} = o |
p:~ -> @x |
p:~ |
Coco 0.6.2
https://github.com/satyr/coco/tree/0.6.2
0.5.2 | 0.6.2 |
---|---|
f(a).p |
f a .p |
f() |
f! |
o{} |
^o |
{o.p, o.q} |
o{p, q} |
{p, q} = r if r? |
{p, q}? = r |
(r) -> {p, q} = r; ... |
({p, q}: r) -> ... |
a.b <<< c if a?b? |
a?b <<< c |
this import x |
import x |
"(#{id})" |
"(#id)" |
/\d/source |
/\d/$ |
[\A \B \C \D] |
[\A to \D] |
[void void] |
[,,] |
if a < b then a else b |
a <? b |
i for i from x |
i for i til x |
for x of xs |
for x of xs |
機能のルーツ
ES.next | Class, Destructuring, Splat |
---|---|
Perl | Conditional Assignment, Implicit Call, Implicit Return, String Interpolation, Post if /for /while , Range, unless /until |
Python | Chained Comparison, Indented Block, Multiline String |
Ruby | super , Variable Scope |
Groovy | Soak (?. ) |
Ruby ぽいと思われがちの CoffeeScript だが、機能の多くは Ruby を通じて Perl から受け継がれたもの。明確に Ruby 由来と言えるのは変数スコープ*1くらいである。
WeakMap uniq
[http://wiki.ecmascript.org/doku.php?id=harmony:weak_maps:title=WeakMap]
で uniq を書いて [https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf:title=indexOf]
版と比較してみた。
Primitive を受け付けない*1ので Object.create(null)
と併用する。
https://gist.github.com/1005856
ちゃんと速いようで安心。
paren-free CoffeeScript
括弧省略言語 CoffeeScript でなるべく負けた気にならないための書法集。
do
Function(js)() # ↓ do Function js
not in/of/instanceof
not (a instanceof B) # ↓ a not instanceof B
セミコロン
[f(a), g(h(b), c), d] # ↓ [f a; g(h b; c); d]
関数呼び出しは右に
f(a) is b # ↓ b is f a
代入も右に(Ruby と同じ)
(a = b) * c # ↓ c * a = b
メソッドチェーン時の例外を利用(ブロック+行頭ドット)
f(a, c if b).g d # ↓ f a, if b c .g d
Coco 0.5.2
https://github.com/satyr/coco/tree/0.5.2
0.4.2 | 0.5.2 |
---|---|
///.../// |
//...// |
if !a? then a else b |
a !? b |
function f(a, b) -> |
function f a, b |
let (a = b) ~> |
let a = b |
new -> |
new |
switch case [a, b] then |
switch case a, b then |
[...a, b] |
a + [b] |
[]join.call a, \- |
a * \- |
String(x)replace /-/g '' |
x - /-/g |
String(x)split \- |
x / \- |
Math.pow(n, m) |
n ** m |