2019-04-21 11:50:48 +08:00

112 lines
5.1 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<article id="wikiArticle">
<div> <div class="blockIndicator nonStandard nonStandardHeader">
<p><strong><span class="icon-only-inline" title="This API has not been standardized."><i class="icon-warning-sign"> </i></span> 非标准</strong><br/>
该特性是非标准的,请尽量不要在生产环境中使用它!</p>
</div></div>
<p><strong><code>function.displayName</code></strong> 属性获取函数的显示名称</p>
<h2 id="Description_描述">Description 描述</h2>
<p>当一个函数的 <code>displayName</code> 属性被定义,这个函数的 <code>displayName</code> 属性将返回显示名称。</p>
<pre><code class="language-javascript">function doSomething() {}
console.log(doSomething.displayName); // "undefined"
var popup = function(content) { console.log(content); };
popup.displayName = 'Show Popup';
console.log(popup.displayName); // "Show Popup"
</code></pre>
<p>可以在函数表达式重定义函数的显示名称<a href="Reference/Functions" title="有关更多示例和说明请参阅有关函数的JavaScript指南。">function expression</a>:</p>
<pre><code class="language-javascript">var object = {
someMethod: function() {}
};
object.someMethod.displayName = 'someMethod';
console.log(object.someMethod.displayName); // logs "someMethod"
try { someMethod } catch(e) { console.log(e); }
// ReferenceError: someMethod is not defined
</code></pre>
<p>可以动态修改函数的显示名称:</p>
<pre><code class="language-javascript">var object = {
// anonymous
someMethod: function(value) {
arguments.callee.displayName = 'someMethod (' + value + ')';
}
};
console.log(object.someMethod.displayName); // "undefined"
object.someMethod('123')
console.log(object.someMethod.displayName); // "someMethod (123)"
</code></pre>
<h2 id="Examples_例子">Examples 例子</h2>
<p>这个显示名称通常在控制台和配置文件中,用它来提醒对它背后的真实函数名 <a href="Reference/Global_Objects/Function/name" title="name 属性返回一个函数声明的名称。"><code>func.name</code></a>的引用。例如:</p>
<p>通过如下的举例,显示的名称应该显示像"function My Function()"</p>
<pre><code class="language-javascript">var a = function() {};
a.displayName = 'My Function';
a; // "function My Function()"</code></pre>
<h2 id="Specifications_规范">Specifications 规范</h2>
<p>不属于任何规范</p>
<h2 id="Browser_compatibility_浏览器兼容性">Browser compatibility 浏览器兼容性</h2>
<p>如果你愿意贡献数据,请访问<a class="external" href="https://github.com/mdn/browser-compat-data" rel="noopener">https://github.com/mdn/browser-compat-data</a>并同时给我们发送推送请求。</p>
<div><div class="blockIndicator warning"><strong><a class="external" href="https://github.com/mdn/browser-compat-data" rel="noopener">We're converting our compatibility data into a machine-readable JSON format</a></strong>.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
<strong><a class="new" href="/zh-CN/docs/MDN/Contribute/Structures/Compatibility_tables" rel="nofollow">Find out how you can help!</a></strong></div>
<div class="htab">
<a id="AutoCompatibilityTable" name="AutoCompatibilityTable"></a>
<ul>
<li class="selected"><a>Desktop</a></li>
<li><a>Mobile</a></li>
</ul>
</div></div>
<div id="compat-desktop">
<table class="compat-table">
<tbody>
<tr>
<th>Feature</th>
<th>Chrome</th>
<th>Firefox (Gecko)</th>
<th>Internet Explorer</th>
<th>Opera</th>
<th>Safari</th>
</tr>
<tr>
<td>Basic support</td>
<td><span style="color: rgb(255, 153, 0);" title="Compatibility unknown; please update this.">?</span></td>
<td><a href="/en-US/Firefox/Releases/13" title="Released on 2012-06-05.">13</a> (13)</td>
<td><span style="color: rgb(255, 153, 0);" title="Compatibility unknown; please update this.">?</span></td>
<td><span style="color: rgb(255, 153, 0);" title="Compatibility unknown; please update this.">?</span></td>
<td><span style="color: rgb(255, 153, 0);" title="Compatibility unknown; please update this.">?</span></td>
</tr>
</tbody>
</table>
</div>
<div id="compat-mobile">
<table class="compat-table">
<tbody>
<tr>
<th>Feature</th>
<th>Android</th>
<th>Chrome for Android</th>
<th>Firefox Mobile (Gecko)</th>
<th>IE Mobile</th>
<th>Opera Mobile</th>
<th>Safari Mobile</th>
</tr>
<tr>
<td>Basic support</td>
<td><span style="color: rgb(255, 153, 0);" title="Compatibility unknown; please update this.">?</span></td>
<td><span style="color: rgb(255, 153, 0);" title="Compatibility unknown; please update this.">?</span></td>
<td><span style="color: rgb(255, 153, 0);" title="Compatibility unknown; please update this.">?</span></td>
<td><span style="color: rgb(255, 153, 0);" title="Compatibility unknown; please update this.">?</span></td>
<td><span style="color: rgb(255, 153, 0);" title="Compatibility unknown; please update this.">?</span></td>
<td><span style="color: rgb(255, 153, 0);" title="Compatibility unknown; please update this.">?</span></td>
</tr>
</tbody>
</table>
</div>
</article>