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

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

@@ -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>