33

Most sites say callee as a property of Function.arguments is deprecated. But some sites go further and say the whole of Functions.argument is deprecated E.g. https://web.archive.org/web/20130313045745/http://aptana.com/reference/api/Arguments.html . Why only mention callee if the whole routine is dead in the water? I only just discovered arguments and it seems incredibly useful E.g: http://hungred.com/how-to/secret-arguments-array-javascript/

Michael M.
  • 10,486
  • 9
  • 18
  • 34
Chris Tolworthy
  • 2,066
  • 4
  • 20
  • 24

5 Answers5

49

Function.arguments is deprecated, but it's only deprecated in favor of the vanilla arguments object that's available within a function. (e.g. using x = arguments[i]; instead of x = theFunc.arguments[i];)

That's now the preferred (and as you say, extremely useful) method for accessing the ordinal arguments received.

Curtis
  • 3,931
  • 1
  • 19
  • 26
Alex K.
  • 171,639
  • 30
  • 264
  • 288
  • This makes sense. If Javascript ever wants some multi-threading support, such global stateful objects are killing. – Stijn de Witt Jan 20 '16 at 22:08
  • Why is `Function.arguments` deprecated though ? It allows you to directly access the arguments of a parent function inside of a nested function, this is something you can't do with the `arguments` object. – doubleOrt Oct 30 '17 at 16:48
  • I posted workaround `getArguments()` functions for Node.js and browser due to this lack of functionality at https://stackoverflow.com/a/49544338/539149 – Zack Morris Mar 28 '18 at 21:30
8

Afaik arguments is deprecated as a property of Function. See this MDN-link, or this one

KooiInc
  • 119,216
  • 31
  • 141
  • 177
2

The Javascript "argument array" — not deprecated, but I would say outdated as of 2021:

The “arguments” keyword is reserved and cannot be used as a parameter name or within the function body as a local variable. This feature was designed to allow an arbitrary amount of arguments when invoking a function without having to specify an arbitrary amount of parameters in the function definition. It is also an outdated way to utilize multiple arguments and is less efficient than the modern rest parameters method.

Here is an example showing preferred practice:

function eat(...food) {
  for (let item in food) {
    console.log("eating " + item);
  } 
  // log the rest parameter
  console.log(food);
}
eat("eggs", "toast", "bacon");
// => eating eggs
// => eating toast
// => eating bacon
// => [ 'eggs', 'toast', 'bacon' ]

The above quote and code sample are from an article titled JavaScript Parameters and Arguments

Purplejacket
  • 1,808
  • 2
  • 25
  • 43
1

callee is deprecated, but the arguments is used in many applications. I don't know if arguments is deprecated. You can use it to get all the parameters of a function, even if there not defined within function( params ).

Most of the time I used when I develop a jQuery plugin. Something like:

$.fn.tooltip = function( method ) {
    if ( methods[method] ) {
      return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
    } else if ( typeof method === 'object' || ! method ) {
      return methods.init.apply( this, arguments );
    } else {
      $.error( 'Method ' +  method + ' does not exist on jQuery.tooltip' );
    }    
  };

As you can see only method is passed as a parameter, but within the first if the arguments is split after the first value. This way you can pass a function name, and all parameters used by this function.

Full example: http://docs.jquery.com/Plugins/Authoring

Niels
  • 48,601
  • 4
  • 62
  • 81
1

No, the arguments array is not deprecated in the latest 5.1 version of the specification (see page 60). The caller object will however only be available if the code is not in strict mode.

Mathias Schwarz
  • 7,099
  • 23
  • 28