File: function.xml

package info (click to toggle)
datatables.js 1.10.21%2Bdfsg-2%2Bdeb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 22,604 kB
  • sloc: javascript: 64,254; xml: 10,441; php: 4,623; sh: 523; makefile: 21
file content (54 lines) | stat: -rw-r--r-- 1,542 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?xml version="1.0" encoding="UTF-8" ?>
<dt-type group="js">
	<name>function</name>
	<summary>Javascript `Function`</summary>

	<description>
	<![CDATA[

Functions are a key component of any programming language, particularly in Javascript which treats functions as first class objects. Functions are created using the construct `function () {}`, `function name () {}` or `new Function()`.

A detailed description of the `Function` type is available on the [Mozilla Developer Network](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function).


## Use in DataTables

Where a parameter is shown as accepting a function type, or a method returning a function type, it indicates that a function can be passed in (be it as a function assigned to a variable, or an anonymous function) / returned.

Functions in DataTables are frequently used for callbacks. For example, using an anonymous function which is executed whenever DataTables performs a draw action (`dt-init drawCallback`):

```js
$('#example').DataTable( {
	drawCallback: function () {
		console.log( 'Table redrawn '+new Date() );
	}
} );
```

Same example assigning the function to a variable:

```js
var draw = function () {
	console.log( 'Table redrawn '+new Date() );
};

$('#example').DataTable( {
	drawCallback: draw
} );
```

And finally, the same example using a named function:

```js
function draw () {
	console.log( 'Table redrawn '+new Date() );
};

$('#example').DataTable( {
	drawCallback: draw
} );
```

	]]>
	</description>
</dt-type>