Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 1063844 of ReferenceError: deprecated caller or arguments usage

  • Revision slug: Web/JavaScript/Reference/Errors/Deprecated_caller_or_arguments_usage
  • Revision title: Deprecated caller or arguments usage
  • Revision id: 1063844
  • Created:
  • Creator: fscholz
  • Is current revision? No
  • Comment

Revision Content

{{jsSidebar("Errors")}}

Message

Warning: ReferenceError: deprecated caller usage
Warning: ReferenceError: deprecated arguments usage 

Error type

A strict-mode-only warning that a {{jsxref("ReferenceError")}} occurred. JavaScript execution won't be halted.

What went wrong?

In strict mode, the {{jsxref("Function.caller")}} or {{jsxref("Function.arguments")}} properties are used and shouldn't be. They are deprecated, because they leak the function caller, are non-standard, hard to optimize and potentially a performance-harmful feature.

Examples

Deprecated function.caller or arguments.callee.caller

{{jsxref("Function.caller")}} and arguments.callee.caller are deprecated (see the reference articles for more information).

"use strict";

function myFunc() {
  if (myFunc.caller == null) {
    return 'The function was called from the top!';
  } else {
    return 'This function\'s caller was ' + myFunc.caller;
  }
}

myFunc();
// Warning: ReferenceError: deprecated caller usage
// "The function was called from the top!"

Function.arguments

{{jsxref("Function.arguments")}} is deprecated (see the reference article for more information).

"use strict";

function f(n) { g(n - 1); }

function g(n) {
  console.log('before: ' + g.arguments[0]);
  if (n > 0) { f(n); }
  console.log('after: ' + g.arguments[0]);
}

f(2);

console.log('returned: ' + g.arguments);
// Warning: ReferenceError: deprecated arguments usage

See also

Revision Source

<div>{{jsSidebar("Errors")}}</div>

<h2 id="Message">Message</h2>

<pre class="syntaxbox">
Warning: ReferenceError: deprecated caller usage
Warning: ReferenceError: deprecated arguments usage 
</pre>

<h2 id="Error_type">Error type</h2>

<p>A strict-mode-only warning that a {{jsxref("ReferenceError")}} occurred. JavaScript execution won't be halted.</p>

<h2 id="What_went_wrong">What went wrong?</h2>

<p>In <a href="/en-US/docs/Web/JavaScript/Reference/Strict_mode">strict mode</a>, the {{jsxref("Function.caller")}} or {{jsxref("Function.arguments")}} properties are used and shouldn't be. They are deprecated, because they leak the function caller, are non-standard, hard to optimize and potentially a performance-harmful feature.</p>

<h2 id="Examples">Examples</h2>

<h3 id="Deprecated_function.caller_or_arguments.callee.caller">Deprecated <code>function.caller</code> or <code>arguments.callee.caller</code></h3>

<p>{{jsxref("Function.caller")}} and <code><a href="/en-US/docs/Web/JavaScript/Reference/Functions/arguments/callee">arguments.callee.caller</a></code> are deprecated (see the reference articles for more information).</p>

<pre class="brush: js example-bad">
"use strict";

function myFunc() {
&nbsp; if (myFunc.caller == null) {
&nbsp;&nbsp;&nbsp; return 'The function was called from the top!';
&nbsp; } else {
&nbsp;&nbsp;&nbsp; return 'This function\'s caller was ' + myFunc.caller;
&nbsp; }
}

myFunc();
// Warning: ReferenceError: deprecated caller usage
// "The function was called from the top!"</pre>

<h3 id="Function.arguments"><code>Function.arguments</code></h3>

<p>{{jsxref("Function.arguments")}} is deprecated (see the reference article for more information).</p>

<pre class="brush: js example-bad">
"use strict";

function f(n) { g(n - 1); }

function g(n) {
  console.log('before: ' + g.arguments[0]);
  if (n &gt; 0) { f(n); }
  console.log('after: ' + g.arguments[0]);
}

f(2);

console.log('returned: ' + g.arguments);
// Warning: ReferenceError: deprecated arguments usage
</pre>

<h2 id="See_also">See also</h2>

<ul>
 <li><a href="/en-US/docs/Web/JavaScript/Reference/Deprecated_and_obsolete_features">Deprecated and obsolete features</a></li>
 <li><a href="/en-US/docs/Web/JavaScript/Reference/Strict_mode">Strict mode</a></li>
 <li>{{jsxref("Function.arguments")}}</li>
 <li>{{jsxref("Function.caller")}} and <code><a href="/en-US/docs/Web/JavaScript/Reference/Functions/arguments/callee">arguments.callee.caller</a></code></li>
</ul>
Revert to this revision