関数名

関数 (JavaScript)

仕様書

Function (Web IDL)

[9] Web IDLFunction は、 任意の引数を受け取り任意の値を返すコールバック関数です >>2

[10] 次の場面で使われています。

歴史

[3] 無限リストと遅延評価: Days on the Moon ( 版) http://nanto.asablo.jp/blog/2008/02/02/2596496

[4] Hawk's W3 Laboratory : JavaScript Notes : JavaScript 深層 : 関数の生成とオブジェクトの結合 ( 版) 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ベースのブラウザだけでした。これらは「関数本体が同等で、かつスコープチェーンが全く同じ」場合に限り複数の関数を結合(恐らく実際には関数を再利用)しています。以下が確認のコードです。

var fs = new Array();
for(var i=0; i<2; i++) {
   fs[i] = function(){ alert(i); };
}

if(fs[0]==fs[1]) {
   alert('結合されています');
} else {
   alert('結合されていません');
}

NN4.XやGeckoベースのブラウザで実行すると「結合されています」と表示され、IEやOpera,KHTMLなどでは「結合されていません」と表示されます。また以下の2例は仕様上結合が認められているが、実際に結合を行う実装が見あたらない例です。いずれも対象となる関数にはスコープチェインの差異があります(差異が外部から観察できるか=実行結果が異なるかどうかとは無関係)。

function A() {
   return function (){ alert('hoge'); };
}

var f1 = A();
var f2 = A();

if(f1==f2) {
   alert('結合されています');
} else {
   alert('結合されていません');
}
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('結合されていません');
}

[7] JS の再帰 (追試) - 冬通りに消え行く制服ガールは、夢物語にリアルを求めない。 - subtech ( 版) http://subtech.g.hatena.ne.jp/cho45/20090318/1237315752

[8] 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.]] ( ( 版)) http://html5.org/tools/web-apps-tracker?from=2683&to=2684

[11] Define .name property for all Function objects. · heycam/webidl@a275e56 ( 版) https://github.com/heycam/webidl/commit/a275e567f07c23cde20d1c8b1dd50574355c0d74

[12] Provide hooks for Content Security Policy (CSP) · Issue #450 · tc39/ecma262 ( 版) https://github.com/tc39/ecma262/issues/450

[13] Implement 'HostEnsureCanCompileStrings'. · w3c/webappsec-csp@69d9779 ( 版) https://github.com/w3c/webappsec-csp/commit/69d9779466c93ffd51d057bfb7ef8dc09d2a5353

[14] Link function objects to ES spec directly. (#387) (tobie著, ) https://github.com/heycam/webidl/commit/95ffce8553831fa99cbfb3da8db906ba08f2a78f

[15] Update definition of function objects to latest ES draft · Issue #280 · heycam/webidl () https://github.com/heycam/webidl/issues/280

[16] Link function objects to ES spec directly. by tobie · Pull Request #387 · heycam/webidl () https://github.com/heycam/webidl/pull/387

[17] もじら組フォーラム [One Topic All View / Re[7]: JavaScriptで関数の内のブロック内の関数定義 / Page: 0] (Mozilla-gumi著, ) http://forum.mozilla.gr.jp/cbbs.cgi?mode=al2&namber=26867&rev=&&KLOG=171

[18] Editorial: make the type of custom element constructors stricter (yuki3著, ) https://github.com/whatwg/html/commit/f8bd887aff17a5ffaf8c50c76b937815c92fc5e4

[19] Specify what typeof should return for exotic objects (TimothyGu著, ) https://github.com/heycam/webidl/commit/5de45d9bc817fb0ce3f498e4ca9c14adbee2d172

[20] typeof operator and platform objects · Issue #512 · heycam/webidl () https://github.com/heycam/webidl/issues/512

[21] JavaScript defines typeof fully now (annevk著, ) https://github.com/heycam/webidl/commit/ed986625a77fad9db2260a4219b9c58d25bb7756

[22] Specify what typeof should return for exotic objects (TimothyGu著, ) https://github.com/heycam/webidl/commit/5de45d9bc817fb0ce3f498e4ca9c14adbee2d172

[23] Specify what typeof should return for exotic objects by TimothyGu · Pull Request #640 · heycam/webidl () https://github.com/heycam/webidl/pull/640

[24] typeof operator and platform objects · Issue #512 · heycam/webidl () https://github.com/heycam/webidl/issues/512

[25] JavaScript defines typeof fully now by annevk · Pull Request #712 · heycam/webidl () https://github.com/heycam/webidl/pull/712

[26] Editorial: Remove 'Strict' arg from FunctionCreate call (jmdyck著, ) https://github.com/whatwg/html/commit/39dd2044f5371cabf4bd9cbb1c24b5a3a08c4166