[removed] is the arguments array deprecated?

后端 未结 4 2057
-上瘾入骨i
-上瘾入骨i 2020-12-15 04:28

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. http://apta

相关标签:
4条回答
  • 2020-12-15 04:40

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

    0 讨论(0)
  • 2020-12-15 04:42

    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.

    0 讨论(0)
  • 2020-12-15 04:48

    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

    0 讨论(0)
  • 2020-12-15 04:50

    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.

    0 讨论(0)
提交回复
热议问题