This article is in need of an editorial review.
This translation is incomplete. Please help translate this article from English.
非標準
This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.
概要
関数の表示名称を表します。
説明
定義されると、displayName プロパティは関数の表示名称を返します。:
function doSomething() {}
alert(doSomething.displayName); // "undefined"
var popup = function(content) { alert(content); };
popup.displayName = 'Show Popup';
alert(popup.displayName); // "Show Popup"
function expression内で表示名称ともに関数を定義できます。:
var object = {
someMethod: function() {}
};
object.someMethod.displayName = 'someMethod';
alert(object.someMethod.displayName); // alerts "someMethod"
try { someMethod } catch(e) { alert(e); }
// ReferenceError: someMethod is not defined
関数のdisplayNameを動的に変更できます。:
var object = {
// anonymous
someMethod: function(value) {
this.displayName = 'someMethod (' + value + ')';
}
};
alert(object.someMethod.displayName); // "undefined"
object.someMethod('123')
alert(object.someMethod.displayName); // "someMethod (123)"
例
関数の名称を表示することは、func.nameを通してコンソールやプロファイラによって普通選ばれます。
コンソールで次のテキストを入力することによって、"function My Function()"のように表示されます。:
var a = function() {};
a.displayName = 'My Function';
a
仕様
すべての仕様では実装されておりません。
ブラウザ実装状況
| 機能 | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| 基本サポート | ? | 13 (13) | ? | ? | ? |
| 機能 | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| 基本サポート | ? | ? | ? | ? | ? | ? |