25.9. The Function Object

The Function object corresponds to a JavaScript function, not to any HTML element.

Constructor

new Function(arg0Name, … , argNName, bodyString) This constructor builds a new function. For instance, the following two forms have the same effect, but the second can be performed inside another routine at run time.

function square(x) { return(x * x); }
square = new Function("x", "return(x * x)");

Properties

arguments From within the body of a function, this property gives an array of arguments used to call the function. Use this property to create variable-argument functions. For example, the following function adds any number of values together.

 function sum() { var total = 0; for(var i=0; i<arguments.length; i++) { total ...

Get Core Web Programming, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.