IIFE

http://benalman.com/news/2010/11/immediately-invoked-function-expression/ について。

「即時実行関数式」は長いので「即行関数」としたい。
そのまま「IIFE」でもいいが検索性に難あり。

書き方
!function(){}()
~function(){}()

+- 、及び括弧で括るのは ASI を妨げるのでよくない。
void は冗長。new は無駄。

値を返す場合は定義と紛らわしいので括るか new する。

r = (function(){}())
r = new function(){}

(function(){})() でもいいが見た目の対称性を考えると上記*1) { 派の人は末尾も開けて (function () {} ()) とすると対称になってよろしい。

*1:同じ理由で波括弧の前には空白を入れないのが好み

**

万が一入った場合に後悔しないよう **実装した

結合の仕方が覚えづらい演算子だと感じていたが、改めて調べるとさもありなん

~2**2 -2**2 2**2**3 assoc prec
Python -5 -4 256 right ** > ~ = -
Ruby 9 -4 256 right ~ > ** > -
Groovy 9 -4 64 left ~ > ** > -

言語によってまちまちだったのだ。

Perl/Python
業界標準Coco の挙動は取り敢えずこれに合わせた。
Ruby
優先順位が単項演算子の間に挟まっている。誰得。
Groovy
Ruby を真似つつ、しかし結合は左に。誰得 ** 2。
追記

一眠りして思い直し、結合則変更した

~2**2 -2**2 2**2**3 assoc prec
Coco 9 4 64 left ~ = - > **

上記言語のどれとも異なるが、そもそもばらばらなので大丈夫だ、問題無い。
理由:

  • 23 のような数学的表記ができない以上、右結合は混乱の元。
  • 二項演算子が単項演算子の優先順位を上回るのは非直感的。
  • (-1) とか書きたくない。

docs.python.org には

The power operator binds more tightly than unary operators on its left; it binds less tightly than unary operators on its right

http://docs.python.org/reference/expressions.html#the-power-operator

とあり、わけがわからないよ。

余談

**= とか今回初めて書いたかも。

Coco 0.4.2

https://github.com/satyr/coco/tree/0.4.2

0.3.2 0.4.2
(x.y ||= {})z ||= [] x!y@z
(-> ...)call x with x then ...
Array(-~x)join s "#{s}" * x
@constructor.static @..static
`L:`; `break L;` :L break L
a?.b a?b
a ?= c.0; b ?= c.1 [a, b] ?= c
[ [1 0]
  [0 1] ]
* * 1 0
  * 0 1

kc2ks

keyconfig の設定を KeySnail に引き継ぐ。

https://gist.github.com/858606

2011-03-24

Fx4 を期に乗り換えるつもりで書いたが、若干の変更のみであっさり動いたため結局 keyconfig を使い続けている。そもそも用途が完全に被るわけではないので両方入れておくと便利。

ES3 8.6.2.3 step 5

https://mail.mozilla.org/pipermail/es-discuss/2011-February/012839.html

[[Prototype]] の ReadOnly*1が子孫に伝播する話。

Object.prototype = 0
Object.prototype + '' // [object Object]

Object.prototype は書き込み禁止なので代入が無視される*2

o = {__proto__: Object}
o.prototype = 1
o.prototype + '' // [object Object]

[[Prototype]] の同名プロパティが書き込み禁止なので代入不可。

o = {__proto__: Object, prototype: 2}
o.prototype = 3
o.prototype // 3

初期化時に隠してしまうと代入可。


Fx3.6.13 で確認。Dmitry の指摘通り、非直感的な仕様だと思う。

*1:ES5 の Writable

*2:strict mode ならエラー

Coco 0.3.2

https://github.com/satyr/coco/tree/0.3.2

0.2.0 0.3.2
f (a) ->
  ...
a <- f
...
o['!'].m().p o'!'m()p
{k: o.k} {o.k}
a = o.a || b; c = o.c || d {a || b, c || d} = o
s += s.0 s.+=0
{}.toString.call(x).slice(8, -1) typeof! x
i for i from 0 til x i for i from x
[null, true, 2, x] [null true 2 x]
[1, 3, 5, 7, 9] [1 to 9 by 2]
f do -> debugger f debugger