JavaScripture
Contribute via GitHub Feedback

JavaScript Function : Object

Functions are reusable pieces of code that can be executed with different parameters.

Function([param1 : String, [param2 : String, [...]]], body : String) : Function

Constructors

new Function([param1 : String, [param2 : String, [...]]], body : String) : Function

Creates a new Function that has the supplied parameter names and body. If any parameter name contains a ',', it will be split on the ',' and each component will be added as a parameter. Unless the body needs to be modified at run time, Functions are typically created with the function keyword.

Example:

Run

Results:

 

Instance Properties

length : Number

The number of parameters specified when the function was defined.

Example:

Run

Results:

 

prototype : Object

The prototype for objects created by calling this function with the new keyword.

Example:

Run

Results:

 

Instance Methods

apply([thisArg : Object, [parameters : Array]]) : Object

Call this with the this value inside the function bound to thisArg and the parameters to the function from parameters. Returns the result of the function call. See Reflect.apply().

Example:

Run

Results:

 

bind(thisArg : Object, [param1 : Object, [param2 : Object, [...]]]) : Function

Returns a new function that, when called, will have this equal to thisArg, the first parameter equal to param1, the second parameter equal to param2, etc.

Example:

Run

Results:

 

call([thisArg : Object, [param1 : Object, [param2 : Object, [...]]]]) : Object

Call this with the this value inside the function bound to thisArg and parameters (param1, param2, ...). Returns the result of the function call.

Example:

Run

Results: