* 仕様書

[REFS[
- [2] [CITE[Web IDL (Second Edition)]] ([TIME[2015-05-27 01:29:33 +09:00]] 版) <http://heycam.github.io/webidl/#common-Function>
]REFS]

* [CODE(JS)@en[Function]] (Web IDL)

[9] [[Web IDL]] の [DFN[[CODE(JS)@en[[[Function]]]]]] は、
任意の[[引数]]を受け取り任意の値を返す[[コールバック関数]]です [SRC[>>2]]。

[10] 次の場面で使われています。
[FIG(short list)[
- [CODE(DOMm)@en[[[setTimeout]]]]
- [CODE(DOMm)@en[[[setInterval]]]]
]FIG]

* 歴史

[3]
[CITE@ja[無限リストと遅延評価: Days on the Moon]] ([TIME[2008-10-19 11:36:30 +09:00]] 版) <http://nanto.asablo.jp/blog/2008/02/02/2596496>

[4] [CITE[Hawk's W3 Laboratory : JavaScript Notes : JavaScript 深層 : 関数の生成とオブジェクトの結合]] ([TIME[2009-01-04 11:54:28 +09:00]] 版) <http://web.archive.org/web/20061018193747/www.hawk.34sp.com/stdpls/jsnotes/jssinso/07_functions.html>

[6] 
>関数式は関数宣言に似ていますが「式(Expression)」なので、式を書くことが出来るあらゆる場所に書くことが出来ます。また関数名は省略可能です。
>関数名を指定した場合、その名前はその関数の中からしかアクセスできません。 
>;;「スコープに関するその他の話題」で解説したcatchと同じく、一時的なオブジェクトをスコープチェーンに追加することで実現されます。もっともIEやNN 4.Xでは外部からもアクセスできてしまうようですが…。 

[5] 
>私が調べた限りオブジェクトの結合を実装しているのはNN4.XとGeckoベースのブラウザだけでした。これらは「関数本体が同等で、かつスコープチェーンが全く同じ」場合に限り複数の関数を結合(恐らく実際には関数を再利用)しています。以下が確認のコードです。
>
[PRE(JS example code)[
var fs = new Array();
for(var i=0; i<2; i++) {
   fs[i] = function(){ alert(i); };
}

if(fs[0]==fs[1]) {
   alert('結合されています');
} else {
   alert('結合されていません');
}
]PRE]
>
NN4.XやGeckoベースのブラウザで実行すると「結合されています」と表示され、IEやOpera,KHTMLなどでは「結合されていません」と表示されます。また以下の2例は仕様上結合が認められているが、実際に結合を行う実装が見あたらない例です。いずれも対象となる関数にはスコープチェインの差異があります(差異が外部から観察できるか=実行結果が異なるかどうかとは無関係)。
>
[PRE(JS example code)[
function A() {
   return function (){ alert('hoge'); };
}

var f1 = A();
var f2 = A();

if(f1==f2) {
   alert('結合されています');
} else {
   alert('結合されていません');
}
]PRE]
>
[PRE(JS example code)[
var objects = [{'foo':'bar'}, {'foo':'hoge'}];
var fs = [];
for(var i=0; i<2; i++) {
   with(objects[i]) {
      fs[i] = function(){ alert(foo); };
   }
}

if(fs[0]==fs[1]) {
   alert('結合されています');
} else {
   alert('結合されていません');
}
]PRE]

[7] [CITE[JS の再帰 (追試) - 冬通りに消え行く制服ガールは、夢物語にリアルを求めない。 - subtech]] ([TIME[2009-05-02 20:29:09 +09:00]] 版) <http://subtech.g.hatena.ne.jp/cho45/20090318/1237315752>

[8] [CITE@en[Web Applications 1.0 r2684 Bring the event handler attribute stuff in line with reality. Make onerror='' and .onerror make sense and compatible with legacy content.]]
( ([TIME[2009-01-21 18:09:00 +09:00]] 版))
<http://html5.org/tools/web-apps-tracker?from=2683&to=2684>

[11] [CITE@en[Define .name property for all Function objects. · heycam/webidl@a275e56]]
([TIME[2016-01-05 11:07:10 +09:00]] 版)
<https://github.com/heycam/webidl/commit/a275e567f07c23cde20d1c8b1dd50574355c0d74>

[12] [CITE@en[Provide hooks for Content Security Policy (CSP) · Issue #450 · tc39/ecma262]]
([TIME[2016-03-04 10:31:41 +09:00]] 版)
<https://github.com/tc39/ecma262/issues/450>

[13] [CITE@en[Implement 'HostEnsureCanCompileStrings'. · w3c/webappsec-csp@69d9779]]
([TIME[2016-04-07 11:07:36 +09:00]] 版)
<https://github.com/w3c/webappsec-csp/commit/69d9779466c93ffd51d057bfb7ef8dc09d2a5353>

[14] [CITE@en[Link function objects to ES spec directly. (#387)]]
([[tobie]]著, [TIME[2017-07-29 07:07:40 +09:00]])
<https://github.com/heycam/webidl/commit/95ffce8553831fa99cbfb3da8db906ba08f2a78f>

[15] [CITE@en[Update definition of function objects to latest ES draft · Issue #280 · heycam/webidl]]
([TIME[2017-07-29 13:29:03 +09:00]])
<https://github.com/heycam/webidl/issues/280>

[16] [CITE@en[Link function objects to ES spec directly. by tobie · Pull Request #387 · heycam/webidl]]
([TIME[2017-07-29 13:29:10 +09:00]])
<https://github.com/heycam/webidl/pull/387>

[17] [CITE@ja[もじら組フォーラム '''['''One Topic All View / Re'''['''7''']''': JavaScriptで関数の内のブロック内の関数定義 / Page: 0''']''']]
([[Mozilla-gumi]]著, [TIME[2017-09-10 16:11:24 +09:00]])
<http://forum.mozilla.gr.jp/cbbs.cgi?mode=al2&namber=26867&rev=&&KLOG=171>

[18] [CITE@en[Editorial: make the type of custom element constructors stricter]]
([[yuki3]]著, [TIME[2018-05-30 00:29:26 +09:00]])
<https://github.com/whatwg/html/commit/f8bd887aff17a5ffaf8c50c76b937815c92fc5e4>

[19] [CITE@en[Specify what typeof should return for exotic objects]]
([[TimothyGu]]著, [TIME[2019-02-26 00:23:05 +09:00]])
<https://github.com/heycam/webidl/commit/5de45d9bc817fb0ce3f498e4ca9c14adbee2d172>

[20] [CITE@en[typeof operator and platform objects · Issue #512 · heycam/webidl]]
([TIME[2019-06-21 17:08:55 +09:00]])
<https://github.com/heycam/webidl/issues/512>

[21] [CITE@en[JavaScript defines typeof fully now]]
([[annevk]]著, [TIME[2019-04-11 17:09:00 +09:00]])
<https://github.com/heycam/webidl/commit/ed986625a77fad9db2260a4219b9c58d25bb7756>

[22] [CITE@en[Specify what typeof should return for exotic objects]]
([[TimothyGu]]著, [TIME[2019-02-26 00:23:05 +09:00]])
<https://github.com/heycam/webidl/commit/5de45d9bc817fb0ce3f498e4ca9c14adbee2d172>

[23] [CITE@en[Specify what typeof should return for exotic objects by TimothyGu · Pull Request #640 · heycam/webidl]]
([TIME[2020-01-12 12:27:29 +09:00]])
<https://github.com/heycam/webidl/pull/640>

[24] [CITE@en[typeof operator and platform objects · Issue #512 · heycam/webidl]]
([TIME[2020-01-12 12:28:07 +09:00]])
<https://github.com/heycam/webidl/issues/512>

[25] [CITE@en[JavaScript defines typeof fully now by annevk · Pull Request #712 · heycam/webidl]]
([TIME[2020-01-12 12:33:36 +09:00]])
<https://github.com/heycam/webidl/pull/712>

[26] [CITE@en[Editorial: Remove 'Strict' arg from FunctionCreate call]]
([[jmdyck]]著, [TIME[2019-06-19 14:57:02 +09:00]])
<https://github.com/whatwg/html/commit/39dd2044f5371cabf4bd9cbb1c24b5a3a08c4166>