-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathtest_arguments.js
51 lines (36 loc) · 931 Bytes
/
test_arguments.js
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
// test_arguments.js
// -----------------
var assert = console.assert;
// All arguments provided
(function(x, y, z) {
assert(arguments);
assert(arguments.length === 3);
assert(x === 1);
assert(y === "Joe");
assert(z['a']);
assert(arguments[0] === 1);
assert(arguments[1] === "Joe");
assert(arguments[2].a === true);
})(1, "Joe", {a: true});
// Missing arguments
(function(x, y, z) {
assert(arguments);
assert(arguments.length === 1);
assert(x === 42);
assert(y === undefined);
assert(z === undefined);
assert(arguments[0] === 42);
})(42);
// Too many arguments
(function(x) {
assert(arguments);
assert(arguments.length === 3);
assert(x === 1);
assert(arguments[0] === 1);
assert(arguments[1] === 2);
assert(arguments[2] === 3);
})(1, 2, 3);
// Parameter named 'arguments' overwrites the arguments object.
(function(arguments) {
assert(typeof arguments == 'number');
})(42);