Skip to content

Latest commit

 

History

History
100 lines (78 loc) · 3.86 KB

File metadata and controls

100 lines (78 loc) · 3.86 KB
title ms.custom ms.date ms.prod ms.reviewer ms.suite ms.technology ms.tgt_pltfrm ms.topic f1_keywords dev_langs helpviewer_keywords ms.assetid caps.latest.revision author ms.author manager
Function Object (JavaScript) | Microsoft Docs
01/18/2017
windows-client-threshold
devlang-javascript
language-reference
function
JavaScript
TypeScript
DHTML
Function object
d3834767-203c-475e-848c-95c423ba15b6
12
mikejo5000
mikejo
ghogen

Function Object (JavaScript)

Creates a new function.

Syntax

function functionName([argname1  [, ...[, argnameN]]])  
{  
   body  
}  

Syntax

  
functionName = new Function( [argname1,  [... argnameN,]] body );  

Parameters

functionName
Required. The name of the newly created function

argname1...argnameN
Optional. A list of arguments the function accepts.

body
Optional. A string that contains the block of [!INCLUDEjavascript] code to be executed when the function is called.

Remarks

The function is a basic data type in [!INCLUDEjavascript]. Syntax 1 creates a function value that [!INCLUDEjavascript] converts into a Function object when necessary. [!INCLUDEjavascript] converts Function objects created by Syntax 2 into function values at the time the function is called.

Syntax 1 is the standard way to create new functions in [!INCLUDEjavascript]. Syntax 2 is an alternative form used to create function objects explicitly.

For example, to declare a function that adds the two arguments passed to it, you can do it in one of two ways:

Example 1

function add(x, y)  
{  
   return(x + y);  
}  

Example 2

var add = function(x, y) {  
     return(x+y);  
}  

In either case, you call the function with a line of code similar to the following:

add(2, 3);  

Note

When you call a function, make sure that you always include the parentheses and any required arguments. Calling a function without parentheses causes the function itself to be returned, instead of the return value of the function.

Properties

0...n Properties |arguments Property | callee Property | caller Property | constructor Property | length Property (Function) | prototype Property

Methods

apply Method | bind Method | call Method | toString Method | valueOf Method

Requirements

[!INCLUDEjsv2]

See Also

function Statement
new Operator
var Statement