[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Functions/arguments [Back]  [Original]

arguments - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

arguments

Baseline Widely available *

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 ..

* Some parts of this feature may have varying levels of support.

arguments , , .

: ES6- , .

: " " , arguments length, . Array, forEach() map(). .

In this article

function func1(a, b, c) {
  console.log(arguments[0]);
  // Expected output: 1

  console.log(arguments[1]);
  // Expected output: 2

  console.log(arguments[2]);
  // Expected output: 3
}

func1(1, 2, 3);

arguments

arguments - , () . arguments . , 0. , 3 , :

js
arguments[0];
arguments[1];
arguments[2];

:

js
arguments[1] = "new value";

arguments Array. , , length. , pop. , :

js
var args = Array.prototype.slice.call(arguments);
var args = [].slice.call(arguments);

// ES2015
const args = Array.from(arguments);
const args = [...arguments];

: slice arguments JavaScript (, V8 ). , arguments. Array :

js
var args =
  arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments);

arguments , . , . arguments.length, , arguments. , , Function.length.

typeof arguments

typeof arguments 'object'.

console.log(typeof arguments); // 'object'

typeof .

//    
console.log(typeof arguments[0]);

arguments

- , arguments Array.from() :

js
var args = Array.from(arguments);
var args = [...arguments];

arguments.callee

, .

arguments.caller

, , .

arguments.length

.

arguments[@@iterator]

Array Iterator, .

,

, . , - . :

js
function myConcat(separator) {
  var args = Array.prototype.slice.call(arguments, 1);
  return args.join(separator);
}

. , :

js
//  "red, orange, blue"
myConcat(", ", "red", "orange", "blue");

//  "elephant; giraffe; lion; cheetah"
myConcat("; ", "elephant", "giraffe", "lion", "cheetah");

//  "sage. basil. oregano. pepper. parsley"
myConcat(". ", "sage", "basil", "oregano", "pepper", "parsley");

, HTML

, HTML- . , : "u", () , "o" ():

js
function list(type) {
  var result = "<" + type + "l><li>";
  var args = Array.prototype.slice.call(arguments, 1);
  result += args.join("</li><li>");
  result += "</li></" + type + "l>"; //  

  return result;
}

, . :

js
var listHTML = list("u", "One", "Two", "Three");

/* listHTML:

"<ul><li>One</li><li>Two</li><li>Three</li></ul>"

*/

,

arguments , .

js
function foo(...args) {
  return arguments;
}
foo(1, 2, 3); // { "0": 1, "1": 2, "2": 3 }

, arguments , , . , , , , 10, 100:

js
function bar(a = 1) {
  arguments[0] = 100;
  return a;
}
bar(10); // 10

100, , :

js
function zoo(a) {
  arguments[0] = 100;
  return a;
}
zoo(10); // 100

, , , arguments, arguments, arguments. :

js
function func(a, b) {
  arguments[0] = 90;
  arguments[1] = 99;
  console.log(a + " " + b);
}

func(1, 2); //90, 99

js
function func(a, b) {
  a = 9;
  b = 99;
  console.log(arguments[0] + " " + arguments[1]);
}

func(3, 4); //9, 99

, , , , :

js
function func(a, b, c = 9) {
  arguments[0] = 99;
  arguments[1] = 98;
  console.log(a + " " + b);
}

func(3, 4); //3, 4

Specification
ECMAScript 2027 LanguageSpecification
# sec-arguments-exotic-objects


Web Proxy Viewer  |  New URL  |  Original Page