JavaScript Kit > JavaScript Reference > Here
Function Object
Last updated: June 9th, 2008
There are several ways to define a function in JavaScript:
Function Statement:
function functionname(arguments){ //standard function
statements...
}
function (arguments){ //unnamed function. JavaScript 1.2.
statements...
}
Constructor:
new Function(arguments, body)
Related Tutorials
- Functions and creating your own functions
- Robust functions via the arguments array
- Using named arguments in JavaScript functions
Properties
| Properties | Description |
|---|---|
| arguments | A local variable that points to the "arguments"
object, which contains all of the arguments passed into the
function. Use "arguments.length" to determine the number of
arguments entered. Note that this is different from the old
arguments[] array, which has been deprecated in JavaScript 1.2. Example(s) |
| caller | References the invoking function, if any. |
| length | Returns the number of named arguments specified. |
| prototype | Prototype property, to add custom properties and methods to this object. |
Methods
| Methods | Description |
|---|---|
| apply() | n/a |
| call() | n/a |
| toString() | n/a |
Examples
Function arguments object
This function below loops through all arguments (assumed to be numeric)
passed into it and returns their sum using the "arguments" object:
function sumof(){
var total=0
for (var i=0; i<arguments.length; i++){
total+=arguments[i]
}
return total
}
//sumof(2,3,4) //returns 9
Reference List
- JavaScript Operators
- JavaScript Statements
- Global functions
- Escape Sequences
- Reserved Words
- Ajax (XMLHttpRequest)
- Anchor
- Applet
- Area
- Array
- Boolean
- Date
- Document
- Event
- Form
- Reset
- Frame
- Function
- History
- Image
- Link
- Location
- Math
- Navigator
- Number
- Object
- RegExp
- Screen
- String
- Style
- window
Partners
Right column
