A Arguments object (Object/core) Cross-references: ECMA 262

A Arguments object (Object/core) Cross-references: ECMA 262 edition 2 section 11.2.4 ECMA 262 edition 3 section 11.2.4 Arguments object (Object/core) An object represented as an array containing the argument values passed to the function when it is called. Availability: ECMAScript edition 2 JavaScript 1.1 JScript 5.5 Internet Explorer 5.5 Netscape 3.0 JavaScript syntax: -myArguments = arguments Object properties: callee, caller, length When you call a function, you can pass zero or more arguments to it from outside. These arguments are available as named variables whose names are defined in the function declaration. However, they are also available as the elements in an array. The arguments array is referenced by the arguments property of the callobject. Since the call object is added to the scope chain, you don’t need to reference the argumentsproperty with an object identifier prefix. The array-based mechanism is useful for those times when you want to implement a function that has a variable number of arguments passed to it according to how and when it is called. A new arguments object is created for each execution context. When the flow of control enters an execution context for a function block, a new arguments object is created. Declared functions, anonymous code, and implementation-specific code all use this technique. When creating the argumentsobject, the initial conditions are set up like this: . The internal Prototype property for the argumentsobject is that returned by calling Object.Prototype. . A property is created with the name callee. The callee property cannot be enumerated. The initial value of the callee property is the function object being executed. Anonymous functions can then be executed recursively if you so desire. . A property named length is created whose value is the number of arguments passed to the function. The length property cannot be enumerated. . Each argument is associated with a property whose name is its integer position in an array of arguments. The arguments are accessed in presentation order. Although the names are strings, they represent purely numeric values and range from 0 to 1 less than the value in the length property. You can enumerate the arguments in a forloop. Note that objects of this type can only exist within a function body in a web browser, because you cannot pass parameters to a script from outside. It is possible that an embedded JavaScript interpreter may provide a hostobject to the main entry point to perform the same function.

Leave a Reply