forked from nkronlage/JavaScripture
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.jsdoc
More file actions
147 lines (105 loc) · 3.7 KB
/
function.jsdoc
File metadata and controls
147 lines (105 loc) · 3.7 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
Function : Object
Functions are reusable pieces of code that can be executed with
different parameters.
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.3
----
Function([param1 : String, [param2 : String, [...]]], body : String) : Function
Same as %%#new_Function_String_String_dotdotdot_String|**new Function(param1, param2, ..., body)**%%.
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.3.1.1
----
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, **Function**s are typically created with the
**function** keyword.
<example>
// The following result in equivalent behavior, but the first
// should be used unless the body changes at run time.
var x = function(x, y) { return x + y; };
var y = Function('x', 'y','return x + y;');
var z = Function('x, y', 'return x + y;');
var w = new Function('x', 'y', 'return x + y;');
</example>
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.3.2.1
----
prototype.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.
<example>
var whatsThis = function() { console.log(this); }
whatsThis.apply('hello');
// Call a function that takes a variable number of args
var numbers = [3, 20, 1, 45];
console.log(Math.max.apply(undefined, numbers));
</example>
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.3.4.3
----
prototype.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>
var whatsThis = function() { console.log(this); }
whatsThis.call('hello');
// Call a function that takes a variable number of args
console.log(Math.max.call(undefined, 3, 20, 1, 45));
</example>
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.3.4.4
----
prototype.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>
var Button = function(content) {
this.content = content;
};
Button.prototype.click = function() {
console.log(this.content + ' clicked');
}
var myButton = new Button('OK');
myButton.click();
var looseClick = myButton.click;
looseClick();
var boundClick = myButton.click.bind(myButton);
boundClick();
// Example showing binding some parameters
var sum = function(a, b) {
return a + b;
};
var add5 = sum.bind(null, 5);
console.log(add5(10));
</example>
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.3.4.5
----
instance.length : Number
The number of parameters specified when the function was defined.
<example>
var add = function(x, y) { return x + y; };
console.log(add.length);
</example>
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.3.5.1
----
instance.prototype : Object
The prototype for objects created by calling this function
with the **new** keyword.
<example>
var Button = function(content) {
this.content = content;
};
Button.prototype.click = function() {
console.log(this.content + ' clicked');
}
var myButton = new Button('OK');
myButton.click();
</example>
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.3.5.2