11.12.2012 Views

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

var instanceName = new Function([arg1 [, arg2 [, ...]] ,] body);<br />

<strong>The</strong> body parameter is a string containing the text that makes up the body of the function. <strong>The</strong><br />

optional argN‘s are the names of the formal parameters the function accepts. For example:<br />

var myAdd = new Function("x", "y", "return x + y");<br />

var sum = myAdd(17, 34);<br />

Properties<br />

arguments[] An implicitly filled and implicitly available (directly usable as "arguments"<br />

from within the function) array of parameters that were passed to the function. This<br />

value is null if the function is not currently executing. (IE4+ (JScript <strong>2.0</strong>+), MOZ, N3+<br />

(<strong>JavaScript</strong> 1.1+), ECMA Edition 1)<br />

arguments.callee <strong>Reference</strong> to the current function. This property is deprecated. (N4+,<br />

MOZ, IE5.5+)<br />

arguments.caller <strong>Reference</strong> to the function that invoked the current function. This<br />

property is deprecated. (N3, IE4+)<br />

arguments.length <strong>The</strong> number of arguments that were passed to the function. (IE4+<br />

(JScript <strong>2.0</strong>+), MOZ, N3+ (<strong>JavaScript</strong> 1.1+), ECMA Edition 1)<br />

arity Numeric value indicating how many arguments the function expects. This property<br />

is deprecated. (N4+, MOZ)<br />

caller <strong>Reference</strong> to the function that invoked the current function or null if called from<br />

the global context. (IE4+ (JScript <strong>2.0</strong>+), MOZ, N3+)<br />

constructor <strong>Reference</strong> to the constructor object that created the object. (IE4+ (JScript<br />

<strong>2.0</strong>+), N3+ (<strong>JavaScript</strong> 1.1+), ECMA Edition 1)<br />

length <strong>The</strong> number of arguments the function expects to be passed. (IE4+ (JScript<br />

<strong>2.0</strong>+), N3+ (<strong>JavaScript</strong> 1.1+), ECMA Edition 1)<br />

prototype <strong>Reference</strong> to the object‘s prototype. (IE4+ (JScript <strong>2.0</strong>+), N3+ (<strong>JavaScript</strong><br />

1.1+), ECMA Edition 1)<br />

Methods<br />

apply(thisArg [, argArray]) Invokes the function with the object referenced by thisArg<br />

as its context (so references to this in the function reference thisArg). <strong>The</strong> optional<br />

parameter argArray contains the list of parameters to pass to the function as it is<br />

invoked. (IE5.5+ (JScript 5.5+), N4.06+ (<strong>JavaScript</strong> 1.3+), MOZ, ECMA Edition 3)<br />

call(thisArg [, arg1 [, arg2 [, ...]]]) Invokes the function with the object referenced by<br />

thisArg as its context (so references to this in the function reference thisArg). <strong>The</strong><br />

optional parameters argN are passed to the function as it is invoked. (IE5.5+ (JScript<br />

5.5+), N4.06+ (<strong>JavaScript</strong> 1.3+), MOZ, ECMA Edition 3)<br />

toString() Returns the string version of the function source. <strong>The</strong> body of built-in and<br />

browser objects will typically be represented by the value "[native code]". (IE4+ (JScript<br />

<strong>2.0</strong>+), N3+ (<strong>JavaScript</strong> 1.1+), MOZ, ECMA Edition 1)<br />

valueOf() Returns the string version of the function source. <strong>The</strong> body of built-in and<br />

browser objects will typically be represented by the value "[native code]". (IE4+ (JScript<br />

<strong>2.0</strong>+), N3+ (<strong>JavaScript</strong> 1.1+), MOZ, ECMA Edition 1)<br />

Support<br />

Supported in IE4+ (JScript <strong>2.0</strong>+), N3+ (<strong>JavaScript</strong> 1.1+), MOZ, ECMAScript Edition 1.<br />

Notes<br />

General examples of functions are found throughout the book, but see Chapter 5 for examples<br />

of the advanced aspects of functions and the Function object.<br />

Global (Built-in Object)<br />

<strong>The</strong> Global object provides methods and constants that can be used freely anywhere in your<br />

scripts. Global is defined to be the globally enclosing context, so this object cannot be<br />

instantiated or even directly accessed; its properties and methods are always within the scope<br />

of an executing script. Its sole purpose is as a catch-all for globally available methods and<br />

constants.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!