语法高亮,滚动条美化,设置页面调整

This commit is contained in:
fofolee
2019-04-19 02:41:09 +08:00
parent 1e8f76c000
commit 359d29ee0b
1590 changed files with 12328 additions and 11441 deletions

View File

@@ -5,7 +5,7 @@
<div><iframe class="interactive interactive-js" frameborder="0" height="250" src="https://interactive-examples.mdn.mozilla.net/pages/js/function-apply.html" width="100%"></iframe></div>
<p class="hidden">The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone <a class="external" href="https://github.com/mdn/interactive-examples" rel="noopener">https://github.com/mdn/interactive-examples</a> and send us a pull request.</p>
<h2 id="Syntax" name="Syntax">语法</h2>
<pre class="syntaxbox"><code><em>func</em>.apply(<em>thisArg</em><em>, [</em><em>argsArray</em>])</code></pre>
<pre><code class="language-javascript"><code><em>func</em>.apply(<em>thisArg</em><em>, [</em><em>argsArray</em>])</code></code></pre>
<h3 id="Parameters" name="Parameters">参数</h3>
<dl>
<dt><code>thisArg</code></dt>
@@ -27,14 +27,14 @@
<h3 id="用_apply_将数组添加到另一个数组">用 <code>apply</code> 将数组添加到另一个数组</h3>
<p>我们可以使用<code>push</code>将元素追加到数组中。并且因为push接受可变数量的参数我们也可以一次推送多个元素。但是如果我们传递一个数组来推送它实际上会将该数组作为单个元素添加而不是单独添加元素因此我们最终得到一个数组内的数组。如果那不是我们想要的怎么办在这种情况下<code>concat</code>确实具有我们想要的行为,但它实际上并不附加到现有数组,而是创建并返回一个新数组。 但是我们想要附加到我们现有的阵列......那么现在呢? 写一个循环?当然不是吗?</p>
<p><code>apply</code>来帮你!</p>
<pre class="brush: js">var array = ['a', 'b'];
<pre><code class="language-javascript">var array = ['a', 'b'];
var elements = [0, 1, 2];
array.push.apply(array, elements);
console.info(array); // ["a", "b", 0, 1, 2]
</pre>
</code></pre>
<h3 id="apply_and_built-in_functions" name="apply_and_built-in_functions">使用<code>apply</code>和内置函数</h3>
<p>聪明的apply用法允许你在某些本来需要写成遍历数组变量的任务中使用内建的函数。在接下里的例子中我们会使用Math.max/Math.min来找出一个数组中的最大/最小值。</p>
<pre class="brush: js">/* 找出数组中最大/小的数字 */
<pre><code class="language-javascript">/* 找出数组中最大/小的数字 */
var numbers = [5, 6, 2, 3, 7];
/* 应用(apply) Math.min/Math.max 内置函数完成 */
@@ -49,10 +49,10 @@ for (var i = 0; i &lt; numbers.length; i++) {
max = numbers[i];
if (numbers[i] &lt; min)
min = numbers[i];
}</pre>
}</code></pre>
<p>但是当心:如果用上面的方式调用<code>apply</code>会有超出JavaScript引擎的参数长度限制的风险。当你对一个方法传入非常多的参数比如一万个就非常有可能会导致越界问题, 这个临界值是根据不同的 JavaScript 引擎而定的JavaScript 核心中已经做了硬编码 <a class="external link-https" href="https://bugs.webkit.org/show_bug.cgi?id=80797" rel="noopener"> 参数个数限制在65536</a>),因为这个限制(实际上也是任何用到超大栈空间的行为的自然表现)是未指定的. 有些引擎会抛出异常。更糟糕的是其他引擎会直接限制传入到方法的参数个数导致参数丢失。举个例子如果某个引擎限制了方法参数最多为4个实际真正的参数个数限制当然要高得多了, 这里只是打个比方), 上面的代码中, 真正通过 <code>apply</code>传到目标方法中的参数为 <code>5, 6, 2, 3</code> 而不是完整的数组。</p>
<p>如果你的参数数组可能非常大,那么推荐使用下面这种策略来处理:将参数数组切块后循环传入目标方法:</p>
<pre class="brush: js">function minOfArray(arr) {
<pre><code class="language-javascript">function minOfArray(arr) {
var min = Infinity;
var QUANTUM = 32768;
@@ -65,43 +65,43 @@ for (var i = 0; i &lt; numbers.length; i++) {
}
var min = minOfArray([5, 6, 2, 3, 7]);
</pre>
</code></pre>
<h3 id="Using_apply_to_chain_constructors" name="Using_apply_to_chain_constructors">使用apply来链接构造器</h3>
<p>你可以使用apply来链接一个对象<a class="new" href="/zh-CN/docs/JavaScript/Reference/Operators/new" rel="nofollow" title="JavaScript/Reference/Operators/new">构造器</a>类似于Java。在接下来的例子中我们会创建一个全局<a href="/zh-CN/docs/JavaScript/Reference/Global_Objects/Function" title="JavaScript/Reference/Global_Objects/Function"><code>Function</code></a> <span style="color: #000000; display: inline !important; float: none; font-family: 'microsoft yahei'; font-size: 18px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 28.8px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal;">对象的</span><span style="color: #000000; font-family: 'microsoft yahei'; font-size: 18px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 28.8px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal;">construct</span><span style="color: #000000; font-family: 'microsoft yahei'; font-size: 18px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 1.6; text-align: left; text-indent: 0px; text-transform: none; white-space: normal;">方法</span> ,来使你能够在构造器中使用一个类数组对象而非参数列表。</p>
<pre class="brush: js">Function.prototype.construct = function (aArgs) {
<pre><code class="language-javascript">Function.prototype.construct = function (aArgs) {
var oNew = Object.create(this.prototype);
this.apply(oNew, aArgs);
return oNew;
};
</pre>
</code></pre>
<div class="note">
<p><strong>注意:</strong> 上面使用的<code>Object.create()</code>方法相对来说比较新。另一种可选的方法,请考虑如下替代方法:</p>
<p>Using <a class="new" href="Reference/Object/__proto__" rel="nofollow" title="此页面仍未被本地化, 期待您的翻译!"><code>Object.__proto__</code></a>:</p>
<pre class="brush: js">Function.prototype.construct = function (aArgs) {
<pre><code class="language-javascript">Function.prototype.construct = function (aArgs) {
var oNew = {};
oNew.__proto__ = this.prototype;
this.apply(oNew, aArgs);
return oNew;
};</pre>
};</code></pre>
<p>使用闭包:</p>
<pre class="brush: js" style="font-style: normal;">Function.prototype.construct = function(aArgs) {
<pre><code class="language-js" style="font-style: normal;">Function.prototype.construct = function(aArgs) {
var fConstructor = this, fNewConstr = function() {
fConstructor.apply(this, aArgs);
};
fNewConstr.prototype = fConstructor.prototype;
return new fNewConstr();
};</pre>
};</code></pre>
<p class="brush: js" style="font-style: normal;">使用 Function 构造器:</p>
<pre class="brush: js">Function.prototype.construct = function (aArgs) {
<pre><code class="language-javascript">Function.prototype.construct = function (aArgs) {
var fNewConstr = new Function("");
fNewConstr.prototype = this.prototype;
var oNew = new fNewConstr();
this.apply(oNew, aArgs);
return oNew;
};</pre>
};</code></pre>
</div>
<p>使用示例:</p>
<pre class="brush: js">function MyConstructor () {
<pre><code class="language-javascript">function MyConstructor () {
for (var nProp = 0; nProp &lt; arguments.length; nProp++) {
this["property" + nProp] = arguments[nProp];
}
@@ -112,7 +112,7 @@ var myInstance = MyConstructor.construct(myArray);
console.log(myInstance.property1); // logs "Hello world!"
console.log(myInstance instanceof MyConstructor); // logs "true"
console.log(myInstance.constructor); // logs "MyConstructor"</pre>
console.log(myInstance.constructor); // logs "MyConstructor"</code></pre>
<div class="note"><strong>注意:</strong> 这个非native的<code>Function.construct</code>方法无法和一些native构造器例如<a href="/zh-CN/docs/JavaScript/Reference/Global_Objects/Date" title="JavaScript/Reference/Global_Objects/Date"><code>Date</code></a>)一起使用。 在这种情况下你必须使用<a href="/zh-CN/docs/JavaScript/Reference/Global_Objects/Function/bind#Bound_functions_used_as_constructors" title="JavaScript/Reference/Global_Objects/Function/bind#Bound_functions_used_as_constructors"><code>Function.bind</code></a>方法例如想象有如下一个数组要用在Date构造器中 <code>[2012, 11, 4]</code>;这时你需要这样写: <code>new (Function.prototype.bind.apply(Date, [null].concat([2012, 11, 4])))()</code> -无论如何这不是最好的实现方式并且也许不该用在任何生产环境中).</div>
<h2 id="规范" style="margin-bottom: 20px; line-height: 30px;">规范</h2>
<table class="standard-table">

View File

@@ -8,7 +8,7 @@
<p>在函数递归调用的时候(在某一刻同一个函数运行了多次,也就是有多套实参),那么 <code>arguments</code> 属性的值是最近一次该函数调用时传入的实参,下面的示例有演示。</p>
<p>如果函数不在执行期间,那么该函数的 <code>arguments</code> 属性的值是 <code>null</code></p>
<h2 id="示例">示例</h2>
<pre class="brush: js">function f(n) { g(n - 1); }
<pre><code class="language-javascript">function f(n) { g(n - 1); }
function g(n) {
console.log('before: ' + g.arguments[0]);
@@ -27,7 +27,7 @@ console.log('函数退出后的 arguments 属性值:' + g.arguments);
// after: 0
// after: 1
// 函数退出后的 arguments 属性值null
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

View File

@@ -4,7 +4,7 @@
<div><iframe class="interactive interactive-js taller" frameborder="0" height="250" src="https://interactive-examples.mdn.mozilla.net/pages/js/function-bind.html" width="100%"></iframe></div>
<p class="hidden">The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone <a class="external" href="https://github.com/mdn/interactive-examples" rel="noopener">https://github.com/mdn/interactive-examples</a> and send us a pull request.</p>
<h2 id="语法">语法</h2>
<pre class="syntaxbox"><code><var>function</var>.bind(<var>thisArg</var>[, <var>arg1</var>[, <var>arg2</var>[, ...]]])</code></pre>
<pre><code class="language-javascript"><code><var>function</var>.bind(<var>thisArg</var>[, <var>arg1</var>[, <var>arg2</var>[, ...]]])</code></code></pre>
<h3 id="参数">参数</h3>
<dl>
<dt><code>thisArg</code></dt>
@@ -33,7 +33,7 @@
<h2 id="示例">示例</h2>
<h3 id="创建绑定函数">创建绑定函数</h3>
<p><code>bind()</code> 最简单的用法是创建一个函数,不论怎么调用,这个函数都有同样的 <strong><code>this</code></strong> 值。JavaScript新手经常犯的一个错误是将一个方法从对象中拿出来然后再调用期望方法中的 <code>this</code> 是原来的对象(比如在回调中传入这个方法)。如果不做特殊处理的话,一般会丢失原来的对象。基于这个函数,用原始的对象创建一个绑定函数,巧妙地解决了这个问题:</p>
<pre class="brush: js">this.x = 9; // 在浏览器中this指向全局的 "window" 对象
<pre><code class="language-javascript">this.x = 9; // 在浏览器中this指向全局的 "window" 对象
var module = {
x: 81,
getX: function() { return this.x; }
@@ -49,10 +49,10 @@ retrieveX();
// 新手可能会将全局变量 x 与 module 的属性 x 混淆
var boundGetX = retrieveX.bind(module);
boundGetX(); // 81
</pre>
</code></pre>
<h3 id="偏函数">偏函数</h3>
<p><code>bind()</code>的另一个最简单的用法是使一个函数拥有预设的初始参数。只要将这些参数(如果有的话)作为<code>bind()</code>的参数写在<code>this</code>后面。当绑定函数被调用时,这些参数会被插入到目标函数的参数列表的开始位置,传递给绑定函数的参数会跟在它们后面。</p>
<pre class="brush: js">function list() {
<pre><code class="language-javascript">function list() {
return Array.prototype.slice.call(arguments);
}
@@ -81,10 +81,10 @@ var result2 = addThirtySeven(5);
var result3 = addThirtySeven(5, 10);
// 37 + 5 = 42 ,第二个参数被忽略
</pre>
</code></pre>
<h3 id="配合_setTimeout">配合 <code>setTimeout</code></h3>
<p>在默认情况下,使用 <a href="/zh-CN/docs/Web/API/Window/setTimeout" title="WindowOrWorkerGlobalScope 混合的 setTimeout()方法设置一个定时器,该定时器在定时器到期后执行一个函数或指定的一段代码。"><code>window.setTimeout()</code></a> 时,<code>this</code> 关键字会指向 <a href="/zh-CN/docs/Web/API/Window" title="The window object represents a window containing a DOM document; the document property points to the DOM document loaded in that window."><code>window</code></a> (或<code>global</code>)对象。当类的方法中需要 <code>this</code> 指向类的实例时,你可能需要显式地把 <code>this</code> 绑定到回调函数,就不会丢失该实例的引用。</p>
<pre class="brush: js"><code>function LateBloomer() {
<pre><code class="language-javascript"><code>function LateBloomer() {
this.petalCount = Math.ceil(Math.random() * 12) + 1;
}
@@ -99,13 +99,13 @@ LateBloomer.prototype.declare = function() {
};
var flower = new LateBloomer();
flower.bloom(); // 一秒钟后, 调用'declare'方法</code></pre>
flower.bloom(); // 一秒钟后, 调用'declare'方法</code></code></pre>
<h3 id="作为构造函数使用的绑定函数">作为构造函数使用的绑定函数</h3>
<div class="warning">
<p><strong>警告</strong> :这部分演示了 JavaScript 的能力并且记录了 <code>bind()</code> 的超前用法。以下展示的方法并不是最佳的解决方案,且可能不应该用在任何生产环境中。</p>
</div>
<p>绑定函数自动适应于使用 <a href="Reference/Operators/new" title="new 运算符创建一个用户定义的对象类型的实例或具有构造函数的内置对象的实例。"><code>new</code></a> 操作符去构造一个由目标函数创建的新实例。当一个绑定函数是用来构建一个值的,原来提供的 <code>this</code> 就会被忽略。不过提供的参数列表仍然会插入到构造函数调用时的参数列表之前。</p>
<pre class="brush: js">function Point(x, y) {
<pre><code class="language-javascript">function Point(x, y) {
this.x = x;
this.y = y;
}
@@ -130,9 +130,9 @@ axisPoint.toString(); // '0,5'
axisPoint instanceof Point; // true
axisPoint instanceof YAxisPoint; // true
new Point(17, 42) instanceof YAxisPoint; // true</pre>
new Point(17, 42) instanceof YAxisPoint; // true</code></pre>
<p>请注意,你不需要做特别的处理就可以用 <a href="Reference/Operators/new" title="new 运算符创建一个用户定义的对象类型的实例或具有构造函数的内置对象的实例。"><code>new</code></a> 操作符创建一个绑定函数。也就是说,你不需要做特别处理就可以创建一个可以被直接调用的绑定函数,即使你更希望绑定函数是用 <a href="Reference/Operators/new" title="new 运算符创建一个用户定义的对象类型的实例或具有构造函数的内置对象的实例。"><code>new</code></a> 操作符来调用。</p>
<pre class="brush: js">// 这个例子可以直接在你的 javascript 控制台运行
<pre><code class="language-javascript">// 这个例子可以直接在你的 javascript 控制台运行
// ...接着上面的代码继续
// 仍然能作为一个普通函数来调用
@@ -140,27 +140,27 @@ new Point(17, 42) instanceof YAxisPoint; // true</pre>
YAxisPoint(13);
emptyObj.x + ',' + emptyObj.y; // '0,13'
</pre>
</code></pre>
<p>如果你希望一个绑定函数要么只能用 <a href="Reference/Operators/new" title="new 运算符创建一个用户定义的对象类型的实例或具有构造函数的内置对象的实例。"><code>new</code></a> 操作符,要么只能直接调用,那你必须在目标函数上显式规定这个限制。</p>
<h3 id="Example:_Creating_shortcuts" name="Example:_Creating_shortcuts">快捷调用</h3>
<p>在你想要为一个需要特定的 <strong><code>this</code></strong> 值的函数创建一个捷径shortcut的时候<code>bind()</code> 也很好用。</p>
<p>你可以用 <a href="Reference/Global_Objects/Array/slice" title="The source for this interactive demo is stored in a GitHub repository. If you'd like to contribute to the interactive demo project, please clone https://github.com/mdn/interactive-examples and send us a pull request."><code>Array.prototype.slice</code></a> 来将一个类似于数组的对象array-like object转换成一个真正的数组就拿它来举例子吧。你可以简单地这样写</p>
<pre class="brush: js">var slice = Array.prototype.slice;
<pre><code class="language-javascript">var slice = Array.prototype.slice;
// ...
slice.apply(arguments);</pre>
slice.apply(arguments);</code></pre>
<p><code>bind()</code>可以使这个过程变得简单。在下面这段代码里面,<code>slice</code> 是 <a href="Reference/Global_Objects/Function/prototype" title="Function.prototype 属性存储了 Function 的原型对象。"><code>Function.prototype</code></a> 的 <a href="Reference/Global_Objects/Function/apply" title="apply() 方法调用一个具有给定this值的函数以及作为一个数组或类似数组对象提供的参数。"><code>apply()</code></a> 方法的绑定函数,并且将 <a href="Reference/Global_Objects/Array/prototype" title="Array.prototype  属性表示 Array 构造函数的原型并允许您向所有Array对象添加新的属性和方法。"><code>Array.prototype</code></a> 的 <a href="Reference/Global_Objects/Array/slice" title="The source for this interactive demo is stored in a GitHub repository. If you'd like to contribute to the interactive demo project, please clone https://github.com/mdn/interactive-examples and send us a pull request."><code>slice()</code></a> 方法作为 <strong><code>this</code></strong> 的值。这意味着我们压根儿用不着上面那个 <code>apply()</code>调用了。</p>
<pre class="brush: js">// 与前一段代码的 "slice" 效果相同
<pre><code class="language-javascript">// 与前一段代码的 "slice" 效果相同
var unboundSlice = Array.prototype.slice;
var slice = Function.prototype.apply.bind(unboundSlice);
// ...
slice(arguments);</pre>
slice(arguments);</code></pre>
<h2 id="Compatibility" name="Compatibility">Polyfill</h2>
<p>你可以将这段代码插入到你的脚本开头,从而使你的 <code>bind()</code> 在没有内置实现支持的环境中也可以部分地使用<code>bind</code></p>
<pre class="brush: js">if (!Function.prototype.bind) {
<pre><code class="language-javascript">if (!Function.prototype.bind) {
Function.prototype.bind = function(oThis) {
if (typeof this !== 'function') {
// closest thing possible to the ECMAScript 5
@@ -191,7 +191,7 @@ slice(arguments);</pre>
return fBound;
};
}</pre>
}</code></pre>
<p>上述算法和实际的实现算法还有许多其他的不同 (尽管可能还有其他不同之处,却没有那个必要去穷尽):</p>
<ul>
<li>这部分实现依赖于<a href="Reference/Global_Objects/Array/slice" title="The source for this interactive demo is stored in a GitHub repository. If you'd like to contribute to the interactive demo project, please clone https://github.com/mdn/interactive-examples and send us a pull request."><code>Array.prototype.slice()</code></a> <a href="Reference/Global_Objects/Array/concat" title="concat() 方法用于合并两个或多个数组。此方法不会更改现有数组,而是返回一个新数组。"><code>Array.prototype.concat()</code></a> <a href="Reference/Global_Objects/Function/call" title="call() 方法调用一个函数, 其具有一个指定的this值和分别地提供的参数(参数的列表)。"><code>Function.prototype.call()</code></a>这些原生方法。</li>

View File

@@ -5,7 +5,7 @@
<div><iframe class="interactive interactive-js" frameborder="0" height="250" src="https://interactive-examples.mdn.mozilla.net/pages/js/function-call.html" width="100%"></iframe></div>
<p class="hidden">The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone <a class="external" href="https://github.com/mdn/interactive-examples" rel="noopener">https://github.com/mdn/interactive-examples</a> and send us a pull request.</p>
<h2 id="语法">语法</h2>
<pre class="syntaxbox"><code><em>fun</em>.call(<em>thisArg</em>, <em>arg1</em>, <em>arg2</em>, ...)</code></pre>
<pre><code class="language-javascript"><code><em>fun</em>.call(<em>thisArg</em>, <em>arg1</em>, <em>arg2</em>, ...)</code></code></pre>
<h3 id="参数">参数</h3>
<dl>
<dt><code>thisArg</code></dt>
@@ -21,7 +21,7 @@
<h2 id="示例">示例</h2>
<h3 id="使用_call_方法调用父构造函数">使用 <code>call</code> 方法调用父构造函数</h3>
<p>在一个子构造函数中,你可以通过调用父构造函数的 <code>call</code> 方法来实现继承,类似于 <code>Java</code> 中的写法。下例中,使用 <code>Food</code><code>Toy </code>构造函数创建的对象实例都会拥有在 <code>Product</code> 构造函数中添加的 <code>name</code> 属性和 <code>price</code> 属性,但 <code>category</code> 属性是在各自的构造函数中定义的。</p>
<pre class="brush: js">function Product(name, price) {
<pre><code class="language-javascript">function Product(name, price) {
this.name = name;
this.price = price;
}
@@ -38,10 +38,10 @@ function Toy(name, price) {
var cheese = new Food('feta', 5);
var fun = new Toy('robot', 40);
</pre>
</code></pre>
<h3 id="使用_call_方法调用匿名函数">使用 <code>call</code> 方法调用匿名函数</h3>
<p>在下例中的 <code>for</code> 循环体内,我们创建了一个匿名函数,然后通过调用该函数的 <code>call</code> 方法,将每个数组元素作为指定的 <code>this</code> 值执行了那个匿名函数。这个匿名函数的主要目的是给每个数组元素对象添加一个 <code>print</code> 方法,这个 <code>print</code> 方法可以打印出各元素在数组中的正确索引号。当然,这里不是必须得让数组元素作为 <code>this</code> 值传入那个匿名函数(普通参数就可以),目的是为了演示 <code>call</code> 的用法。</p>
<pre class="brush: js">var animals = [
<pre><code class="language-javascript">var animals = [
{ species: 'Lion', name: 'King' },
{ species: 'Whale', name: 'Fail' }
];
@@ -55,10 +55,10 @@ for (var i = 0; i &lt; animals.length; i++) {
this.print();
}).call(animals[i], i);
}
</pre>
</code></pre>
<h3 id="使用_call_方法调用函数并且指定上下文的_'this'">使用 <code>call</code> 方法调用函数并且指定上下文的 '<code>this</code>'</h3>
<p>在下面的例子中,当调用 <code>greet</code> 方法的时候,该方法的<code>this</code>值会绑定到 <code>obj</code> 对象。</p>
<pre class="brush: js">function greet() {
<pre><code class="language-javascript">function greet() {
var reply = [this.animal, 'typically sleep between', this.sleepDuration].join(' ');
console.log(reply);
}
@@ -68,20 +68,20 @@ var obj = {
};
greet.call(obj); // cats typically sleep between 12 and 16 hours
</pre>
</code></pre>
<h3 id="使用_call_方法调用函数并且不指定第一个参数argument" style="margin-bottom: 20px; line-height: 30px;">使用 <code><strong>call</strong></code> 方法调用函数并且不指定第一个参数(<code>argument</code></h3>
<p>在下面的例子中,我们调用了 <code>display</code> 方法,但并没有传递它的第一个参数。如果没有传递第一个参数,<code>this</code> 的值将会被绑定为全局对象。</p>
<pre class="brush: js">var sData = 'Wisen';
<pre><code class="language-javascript">var sData = 'Wisen';
function display() {
console.log('sData value is %s ', this.sData);
}
display.call(); // sData value is Wisen</pre>
display.call(); // sData value is Wisen</code></pre>
<div class="note">
<p><strong>注意:</strong>在严格模式下,<code>this</code> 的值将会是 <code>undefined</code>。见下文。</p>
</div>
<pre class="brush: js">'use strict';
<pre><code class="language-javascript">'use strict';
var sData = 'Wisen';
@@ -89,7 +89,7 @@ function display() {
console.log('sData value is %s ', this.sData);
}
display.call(); // Cannot read the property of 'sData' of undefined</pre>
display.call(); // Cannot read the property of 'sData' of undefined</code></pre>
<h2 id="规范" style="margin-bottom: 20px; line-height: 30px;">规范</h2>
<table class="standard-table">
<tbody>

View File

@@ -11,36 +11,36 @@
<p>该属性的常用形式<code>arguments.callee.caller</code>替代了被废弃的 <a href="/zh-cn/JavaScript/Reference/Functions_and_function_scope/arguments/caller" title="zh-cn/JavaScript/Reference/Functions_and_function_scope/arguments/caller">arguments.caller</a>.</p>
<h3 id="Notes" name="Notes">备注</h3>
<p>注意,在使用递归调用时, 你不能使用此属性来重现出调用栈.请考虑以下代码:</p>
<pre class="brush: js">function f(n) { g(n-1) }
<pre><code class="language-javascript">function f(n) { g(n-1) }
function g(n) { if(n&gt;0) f(n); else stop() }
f(2)
</pre>
</code></pre>
<p><code>stop()函数被调用时,调用栈是这样的</code>:</p>
<pre class="brush: js">f(2) -&gt; g(1) -&gt; f(1) -&gt; g(0) -&gt; stop()
</pre>
<pre><code class="language-javascript">f(2) -&gt; g(1) -&gt; f(1) -&gt; g(0) -&gt; stop()
</code></pre>
<p>由于下面的表达式为 true(只保留函数最后一次被调用时的caller):</p>
<pre class="brush: js">stop.caller === g &amp;&amp; f.caller === g &amp;&amp; g.caller === f
</pre>
<pre><code class="language-javascript">stop.caller === g &amp;&amp; f.caller === g &amp;&amp; g.caller === f
</code></pre>
<p>所以如果你尝试在<code>stop()</code>函数中获取调用栈的话:</p>
<pre class="brush: js">var f = stop;
<pre><code class="language-javascript">var f = stop;
var stack = "调用栈:";
while (f) {
stack += "\n" + f.name;
f = f.caller;
}
</pre>
</code></pre>
<p>则上面的代码会进入一个死循环.</p>
<p>有一个特殊属性 <code>__caller__</code>, 可以返回调用当前函数的函数的活动对象(可以用来重现出整个调用栈), 但由于安全原因的考虑,该属性已被删除.</p>
<h2 id="Examples" name="Examples">例子</h2>
<h3 id="Example:_Checking_the_value_of_a_function.27s_caller_property" name="Example:_Checking_the_value_of_a_function.27s_caller_property">例子: 检测一个函数的<code>caller</code>属性的值</h3>
<p>下例用来得出一个函数是被谁调用的<code>.</code></p>
<pre class="brush: js">function myFunc() {
<pre><code class="language-javascript">function myFunc() {
if (myFunc.caller == null) {
return ("<span><span class="string">该函数在全局作用域内被调用</span></span>!");
} else
return ("调用我的是函数是" + myFunc.caller);
}
</pre>
</code></pre>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
<p>Function.caller目前被所有主流浏览器支持: Firefox, Safari, Chrome, Opera 和 IE. <a class="external" href="http://dl.dropbox.com/u/534786/callertest.html" rel="noopener" title="http://dl.dropbox.com/u/534786/callertest.html"><span style="text-decoration: underline;">查看检测结果</span></a>.</p>
</article>

View File

@@ -6,7 +6,7 @@
<p><strong><code>function.displayName</code></strong> 属性获取函数的显示名称</p>
<h2 id="Description_描述">Description 描述</h2>
<p>当一个函数的 <code>displayName</code> 属性被定义,这个函数的 <code>displayName</code> 属性将返回显示名称。</p>
<pre class="brush: js">function doSomething() {}
<pre><code class="language-javascript">function doSomething() {}
console.log(doSomething.displayName); // "undefined"
@@ -15,9 +15,9 @@ var popup = function(content) { console.log(content); };
popup.displayName = 'Show Popup';
console.log(popup.displayName); // "Show Popup"
</pre>
</code></pre>
<p>可以在函数表达式重定义函数的显示名称<a href="Reference/Functions" title="有关更多示例和说明请参阅有关函数的JavaScript指南。">function expression</a>:</p>
<pre class="brush: js">var object = {
<pre><code class="language-javascript">var object = {
someMethod: function() {}
};
@@ -27,9 +27,9 @@ console.log(object.someMethod.displayName); // logs "someMethod"
try { someMethod } catch(e) { console.log(e); }
// ReferenceError: someMethod is not defined
</pre>
</code></pre>
<p>可以动态修改函数的显示名称:</p>
<pre class="brush: js">var object = {
<pre><code class="language-javascript">var object = {
// anonymous
someMethod: function(value) {
arguments.callee.displayName = 'someMethod (' + value + ')';
@@ -40,14 +40,14 @@ console.log(object.someMethod.displayName); // "undefined"
object.someMethod('123')
console.log(object.someMethod.displayName); // "someMethod (123)"
</pre>
</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 class="brush: js">var a = function() {};
<pre><code class="language-javascript">var a = function() {};
a.displayName = 'My Function';
a; // "function My Function()"</pre>
a; // "function My Function()"</code></pre>
<h2 id="Specifications_规范">Specifications 规范</h2>
<p>不属于任何规范</p>
<h2 id="Browser_compatibility_浏览器兼容性">Browser compatibility 浏览器兼容性</h2>

View File

@@ -6,21 +6,21 @@
<h2 id="概述">概述</h2>
<p>判断一个函数是否是一个<a href="/zh-cn/JavaScript/Guide/Iterators_and_Generators#Generators.3a_a_better_way_to_build_Iterators" title="zh-cn/Core JavaScript 1.5 Guide/Iterators and Generators#Generators.3a a better way to build Iterators">生成器</a>.</p>
<h2 id="语法">语法</h2>
<pre class="syntaxbox"><code><var>fun</var>.isGenerator()</code></pre>
<pre><code class="language-javascript"><code><var>fun</var>.isGenerator()</code></code></pre>
<h2 id="描述">描述</h2>
<p>该方法用来判断一个函数是否是一个<a href="/zh-cn/JavaScript/Guide/Iterators_and_Generators#Generators.3a_a_better_way_to_build_Iterators" title="zh-cn/Core JavaScript 1.5 Guide/Iterators and Generators#Generators.3a a better way to build Iterators">生成器</a>.</p>
<h2 id="例子">例子</h2>
<pre class="brush: js">function f() {}
<pre><code class="language-javascript">function f() {}
function* g() {
  yield 42;
}
console.log("f.isGenerator() = " + f.isGenerator());
console.log("g.isGenerator() = " + g.isGenerator());
</pre>
</code></pre>
<p>上面代码的输出结果为</p>
<pre>f.isGenerator() = false
g.isGenerator() = true
</pre>
</code></pre>
<h2 id="相关链接">相关链接</h2>
<ul>
<li><a href="/zh-cn/JavaScript/Guide/Iterators_and_Generators" title="zh-cn/Core JavaScript 1.5 Guide/Iterators and Generators">迭代器和生成器</a></li>

View File

@@ -32,7 +32,7 @@
<h3 id="Function.prototype_对象的属性"><code>Function</code>.prototype 对象的属性</h3>
<p> <a href="Reference/Global_Objects/Function/prototype" title="Function.prototype 属性存储了 Function 的原型对象。"><code>Function.prototype</code></a>  对象的 length 属性值为 0 。</p>
<h2 id="Examples" name="Examples">示例</h2>
<pre class="brush: js">console.log(Function.length); /* 1 */
<pre><code class="language-javascript">console.log(Function.length); /* 1 */
console.log((function() {}).length); /* 0 */
console.log((function(a) {}).length); /* 1 */
@@ -43,7 +43,7 @@ console.log((function(...args) {}).length);
console.log((function(a, b = 1, c) {}).length);
// 1, only parameters before the first one with
// a default value is counted</pre>
// a default value is counted</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>

View File

@@ -28,23 +28,23 @@
<h2 id="示例">示例</h2>
<h3 id="函数声明的名称">函数声明的名称</h3>
<p> <code>name</code> 属性返回一个函数声明的名称。</p>
<pre class="brush:js">function doSomething() { }
<pre><code class="language-js">function doSomething() { }
doSomething.name; // "doSomething" 
</pre>
</code></pre>
<h3 id="构造函数的名称">构造函数的名称</h3>
<p>使用<code>new Function(...)</code>语法创建的函数或只是 <code>Function(...) create</code> <a href="Reference/Function" title="此页面仍未被本地化, 期待您的翻译!"><code>Function</code></a>对象及其名称为“anonymous”。</p>
<pre class="brush: js">(new Function).name; // "anonymous"</pre>
<pre><code class="language-javascript">(new Function).name; // "anonymous"</code></pre>
<h3 id="推断函数名称">推断函数名称</h3>
<p>变量和方法可以从句法位置推断匿名函数的名称ECMAScript 2015中新增</p>
<pre class="brush: js">var f = function() {};
<pre><code class="language-javascript">var f = function() {};
var object = {
someMethod: function() {}
};
console.log(f.name); // "f"
console.log(object.someMethod.name); // "someMethod"</pre>
console.log(object.someMethod.name); // "someMethod"</code></pre>
<p style="color: rgb(77, 78, 83);">你可以在 <a href="Reference/Operators/Function" title="function 关键字可以用来在一个表达式中定义一个函数。">函数表达式</a>中定义函数的名称:</p>
<pre class="brush:js">var object = {
<pre><code class="language-js">var object = {
someMethod: function object_someMethod() {}
};
@@ -52,70 +52,70 @@ console.log(object.someMethod.name); // "object_someMethod"
try { object_someMethod } catch(e) { alert(e); }
// ReferenceError: object_someMethod is not defined
</pre>
</code></pre>
<p>你不能更改函数的名称,此属性是只读的:</p>
<div class="hidden">
<p>Example below contradicts with what is said at the beginning of this section and doesn't work as described.</p>
</div>
<pre class="brush: js">var object = {
<pre><code class="language-javascript">var object = {
// anonymous
someMethod: function() {}
};
object.someMethod.name = 'otherMethod';
console.log(object.someMethod.name); // someMethod</pre>
console.log(object.someMethod.name); // someMethod</code></pre>
<p>要更改它,可以使用<a href="Reference/Global_Objects/Object/defineProperty" title="Object.defineProperty() 方法会直接在一个对象上定义一个新属性,或者修改一个对象的现有属性, 并返回这个对象。"><code>Object.defineProperty()</code></a></p>
<h3 id="简写方法的名称">简写方法的名称</h3>
<pre class="brush: js">var o = {
<pre><code class="language-javascript">var o = {
foo(){}
};
o.foo.name; // "foo";</pre>
o.foo.name; // "foo";</code></pre>
<h3 id="绑定函数的名称">绑定函数的名称</h3>
<p><a href="Reference/Global_Objects/Function/bind" title="bind()方法创建一个新的函数在调用时设置this关键字为提供的值。并在调用新函数时将给定参数列表作为原函数的参数序列的前若干项。"><code>Function.bind()</code></a> 所创建的函数将会在函数的名称前加上"bound " 。</p>
<pre class="brush: js">function foo() {};
foo.bind({}).name; // "bound foo"</pre>
<pre><code class="language-javascript">function foo() {};
foo.bind({}).name; // "bound foo"</code></pre>
<h3 id="getters_和_setters_的函数名">getters 和 setters 的函数名</h3>
<p>当通过 <code><a href="Reference/Functions/get">get</a></code> 和 <code><a href="Reference/Functions/set">set</a></code> 访问器来存取属性时, "get" 或 "set" 会出现在函数名称前。</p>
<pre class="brush: js">var o = {
<pre><code class="language-javascript">var o = {
get foo(){},
set foo(x){}
};
var descriptor = Object.getOwnPropertyDescriptor(o, "foo");
descriptor.get.name; // "get foo"
descriptor.set.name; // "set foo";</pre>
descriptor.set.name; // "set foo";</code></pre>
<h3 id="类中的函数名称">类中的函数名称</h3>
<p>你可以使用<code>obj.constructor.name</code>来检查对象的“类”(但请务必阅读以下警告):</p>
<pre class="brush: js">function Foo() {} // ES2015 Syntax: class Foo {}
<pre><code class="language-javascript">function Foo() {} // ES2015 Syntax: class Foo {}
var fooInstance = new Foo();
console.log(fooInstance.constructor.name); // logs "Foo"</pre>
console.log(fooInstance.constructor.name); // logs "Foo"</code></pre>
<div class="warning">
<p><strong>警告:</strong>脚本解释器只有在函数没有名为name的属性时才会设置内置的<code>Function.name</code>属性(参见 <a class="external" href="https://www.ecma-international.org/ecma-262/6.0/#sec-setfunctionname" rel="noopener">9.2.11 of the ECMAScript2015 Language Specification</a>。但是ES2015规定由关键字<em>static</em>修饰的静态方法也会被认为是类的属性ECMAScript2015, <a class="external" href="https://www.ecma-international.org/ecma-262/6.0/#sec-runtime-semantics-classdefinitionevaluation" rel="noopener">14.5.14.21.b</a> + <a class="external" href="https://www.ecma-international.org/ecma-262/6.0/#sec-object-initializer-runtime-semantics-propertydefinitionevaluation" rel="noopener">12.2.6.9</a>)。</p>
</div>
<p>因此,我们无法获取具有静态方法属性<code>name()</code>的几乎任何类的类名称:</p>
<pre class="brush: js">class Foo {
<pre><code class="language-javascript">class Foo {
constructor() {}
static name() {}
}
</pre>
</code></pre>
<p>使用<code>static name()</code>方法<code>Foo.name</code>不再保存实际的类名称,而是引用<code>name()</code>函数对象。 ES2015语法中的上述类定义将在Chrome或Firefox中运行类似于ES5语法中的以下代码段</p>
<pre class="brush: js">function Foo() {}
<pre><code class="language-javascript">function Foo() {}
Object.defineProperty(Foo, 'name', { writable: true });
Foo.name = function() {};
</pre>
</code></pre>
<p>通过<code>fooInstance.constructor.name</code>获取<code>fooInstance</code>类不会给我们所有的类名,而是静态类方法的引用。 例如:</p>
<pre class="brush: js">var fooInstance = new Foo();
console.log(fooInstance.constructor.name); // logs function name()</pre>
<pre><code class="language-javascript">var fooInstance = new Foo();
console.log(fooInstance.constructor.name); // logs function name()</code></pre>
<p>你也可以从ES5语法示例中看到在Chrome或Firefox的中静态定义的<code>Foo.name</code>变得可写。内置定义在没有自定义静态定义时是只读的:</p>
<pre class="brush: js">Foo.name = 'Hello';
<pre><code class="language-javascript">Foo.name = 'Hello';
console.log(Foo.name);
//如果Foo具有静态name()属性则输出“Hello”否则为“Foo”
</pre>
</code></pre>
<p>因此,你不能依赖内置的<code>Function.name</code>属性来保持一个类的名称。</p>
<h3 id="Symbol作为函数名称">Symbol作为函数名称</h3>
<p>如果<a href="Reference/Global_Objects/Symbol" title='Symbol()函数会返回symbol类型的值该类型具有静态属性和静态方法。它的静态属性会暴露几个内建的成员对象它的静态方法会暴露全局的symbol注册且类似于内建对象类但作为构造函数来说它并不完整因为它不支持语法"new Symbol()"。'><code>Symbol</code></a> 被用于函数名称并且这个symbol具有相应的描述符那么方法的名字就是方括号中的描述符。</p>
<pre class="brush: js">var sym1 = Symbol("foo");
<pre><code class="language-javascript">var sym1 = Symbol("foo");
var sym2 = Symbol();
var o = {
[sym1]: function(){},
@@ -124,29 +124,29 @@ var o = {
o[sym1].name; // "[foo]"
o[sym2].name; // ""
</pre>
</code></pre>
<h2 id="JavaScript_压缩和_minifiers">JavaScript 压缩和 minifiers</h2>
<div class="warning">
<p><strong>警告:</strong>当使用<code>Function.name</code>和那些JavaScript压缩器minifiers或混淆器进行源码转换时要小心。这些工具通常用作JavaScript构建管道的一部分以在程序部署到生产之前减少程序的大小。但这种转换通常会在构建时更改函数的名称。</p>
</div>
<p>例如下面的代码:</p>
<pre class="brush: js">function Foo() {};
<pre><code class="language-javascript">function Foo() {};
var foo = new Foo();
if (foo.constructor.name === 'Foo') {
console.log("'foo' is an instance of 'Foo'");
} else {
console.log('Oops!');
}</pre>
}</code></pre>
<p>可能被压缩为:</p>
<pre class="brush: js">function a() {};
<pre><code class="language-javascript">function a() {};
var b = new a();
if (b.constructor.name === 'Foo') {
console.log("'foo' is an instance of 'Foo'");
} else {
console.log('Oops!');
}
</pre>
</code></pre>
<p>在未压缩版本中,程序运行到真实分支并打印<code>'foo' is an instance of 'Foo'</code>。 而在压缩版本中它的行为不同并且进入else分支。如果您依赖于<code>Function.name</code>,就像上面的示例一样,确保您的构建管道不会更改函数名称,也不要假定函数具有特定的名称。</p>
<article>
<h2 id="规范">规范</h2>

View File

@@ -8,9 +8,9 @@
<h2 id="Summary" name="Summary">概述</h2>
<p>返回函数的源代码的字符串表示.</p>
<h2 id="Syntax" name="Syntax">语法</h2>
<pre class="syntaxbox"><code><var>function</var>.toSource();
<pre><code class="language-javascript"><code><var>function</var>.toSource();
Function.toSource();
</code></pre>
</code></code></pre>
<h3 id="Parameters" name="Parameters">参数</h3>
<p></p>
<h2 id="Description" name="Description">描述</h2>
@@ -19,9 +19,9 @@ Function.toSource();
<ul>
<li>对于内置的<code>Function</code>对象,<code>toSource</code>返回下面的字符串:</li>
</ul>
<pre class="brush: js"><code>function Function() {
<pre><code class="language-javascript"><code>function Function() {
[native code]
}</code></pre>
}</code></code></pre>
<ul>
<li>对于自定义函数来说, <code>toSource返回能定义该函数</code>的Javascript源码.</li>
</ul>

View File

@@ -3,18 +3,18 @@
<p><strong><code>toString()</code> </strong>方法返回一个表示当前函数源代码的字符串。</p>
<div><iframe class="interactive interactive-js" frameborder="0" height="250" src="https://interactive-examples.mdn.mozilla.net/pages/js/function-tostring.html" width="100%"></iframe></div>
<h2 id="Syntax" name="Syntax">语法</h2>
<pre class="syntaxbox"><code><var>function</var>.toString()</code></pre>
<pre><code class="language-javascript"><code><var>function</var>.toString()</code></code></pre>
<h3 id="返回值">返回值</h3>
<p>表示函数源代码的一个字符串</p>
<h2 id="Description" name="Description">描述</h2>
<p><a href="Reference/Function" title="此页面仍未被本地化, 期待您的翻译!"><code>Function</code></a>对象覆盖了从<a href="Reference/Global_Objects/Object" title="Object 构造函数创建一个对象包装器。"><code>Object</code></a>继承来的<a href="Reference/Global_Objects/Object/toString" title="toString() 方法返回一个表示该对象的字符串。"><code>toString</code></a> 方法。对于用户定义的 <a href="Reference/Function" title="此页面仍未被本地化, 期待您的翻译!"><code>Function</code></a> 对象,<code>toString</code>方法返回一个字符串,其中包含用于定义函数的源文本段。</p>
<p><a href="Reference/Function" title="此页面仍未被本地化, 期待您的翻译!"><code>Function</code></a>需要转换为字符串时,通常会自动调用函数的 <code>toString </code>方法。</p>
<p><code>this</code> 不是 <code>Function </code>对象,则 <code>toString()</code> 方法将抛出 <a href="Reference/Global_Objects/TypeError" title="TypeError类型错误 对象用来表示值的类型非预期类型时发生的错误。"><code>TypeError</code></a>  ("Function.prototype.toString called on incompatible object") 异常,比如 <a href="Reference/Global_Objects/Proxy" title="Proxy 对象用于定义基本操作的自定义行为(如属性查找,赋值,枚举,函数调用等)。"><code>Proxy</code></a> 对象就会抛出异常。</p>
<pre class="brush: js example-bad">Function.prototype.toString.call('foo'); // TypeError
</pre>
<pre><code class="language-js example-bad">Function.prototype.toString.call('foo'); // TypeError
</code></pre>
<p>如果是在内置函数或由 <code>Function.prototype.bind </code>返回的函数上调用 <code>toString()</code>,则<code>toString()</code> 返回原生代码字符串,如下</p>
<pre class="brush: js">"function () {\n    [native code]\n}"
</pre>
<pre><code class="language-javascript">"function () {\n    [native code]\n}"
</code></pre>
<p>若是在由 <code>Function</code> 构造器生成的函数上调用 <code>toString()</code> ,则 <code>toString()</code> 返回创建后的函数源码,包括形参和函数体,函数名为 "anonymous"。</p>
<h2 id="示例">示例</h2>
<table class="standard-table">
@@ -28,71 +28,71 @@
<tr>
<td>
<pre>
function f(){}</pre>
function f(){}</code></pre>
</td>
<td>
<pre>
"function f(){}"</pre>
"function f(){}"</code></pre>
</td>
</tr>
<tr>
<td>
<pre>
class A { a(){} }</pre>
class A { a(){} }</code></pre>
</td>
<td>
<pre>
"class A { a(){} }"</pre>
"class A { a(){} }"</code></pre>
</td>
</tr>
<tr>
<td>
<pre>
function* g(){}</pre>
function* g(){}</code></pre>
</td>
<td>
<pre>
"function* g(){}"</pre>
"function* g(){}"</code></pre>
</td>
</tr>
<tr>
<td>
<pre>
a =&gt; a</pre>
a =&gt; a</code></pre>
</td>
<td>
<pre>
"a =&gt; a"</pre>
"a =&gt; a"</code></pre>
</td>
</tr>
<tr>
<td>
<pre>
({ a(){} }.a)</pre>
({ a(){} }.a)</code></pre>
</td>
<td>
<pre>
"a(){}"</pre>
"a(){}"</code></pre>
</td>
</tr>
<tr>
<td>
<pre>
({ *a(){} }.a)</pre>
({ *a(){} }.a)</code></pre>
</td>
<td>
<pre>
"*a(){}"</pre>
"*a(){}"</code></pre>
</td>
</tr>
<tr>
<td>
<pre>
({ [0](){} }[0])</pre>
({ [0](){} }[0])</code></pre>
</td>
<td>
<pre>
"[0](){}"</pre>
"[0](){}"</code></pre>
</td>
</tr>
<tr>
@@ -100,11 +100,11 @@ a =&gt; a</pre>
<pre>
Object.getOwnPropertyDescriptor({
  get a(){}
}, "a").get</pre>
}, "a").get</code></pre>
</td>
<td>
<pre>
"get a(){}"</pre>
"get a(){}"</code></pre>
</td>
</tr>
<tr>
@@ -112,41 +112,41 @@ Object.getOwnPropertyDescriptor({
<pre>
Object.getOwnPropertyDescriptor({
  set a(x){}
}, "a").set</pre>
}, "a").set</code></pre>
</td>
<td>
<pre>
"set a(x){}"</pre>
"set a(x){}"</code></pre>
</td>
</tr>
<tr>
<td>
<pre>
Function.prototype.toString</pre>
Function.prototype.toString</code></pre>
</td>
<td>
<pre>
"function toString() { [native code] }"</pre>
"function toString() { [native code] }"</code></pre>
</td>
</tr>
<tr>
<td>
<pre>
(function f(){}.bind(0))</pre>
(function f(){}.bind(0))</code></pre>
</td>
<td>
<pre>
"function () { [native code] }"</pre>
"function () { [native code] }"</code></pre>
</td>
</tr>
<tr>
<td>
<pre>
Function("a", "b")</pre>
Function("a", "b")</code></pre>
</td>
<td>
<pre>
"function anonymous(a\n) {\nb\n}"</pre>
"function anonymous(a\n) {\nb\n}"</code></pre>
</td>
</tr>
</tbody>