-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest.js
More file actions
64 lines (49 loc) · 1.29 KB
/
test.js
File metadata and controls
64 lines (49 loc) · 1.29 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
var funstuff = require('./build/Release/funstuff');
var book = new funstuff.Book();
var p1 = new funstuff.Person();
p1.firstname = 'Arthur';
p1.lastname = 'Clarke';
p1.birthday = new Date(1917, 11, 16); // month is zero-based
console.log(p1.firstname + " " + p1.lastname + ": "+ p1.birthday);
book[0] = ['Peter', 'Hamilton', new Date(1960, 02, 02)];
console.log(book.length());
book.add(p1);
console.log(book.length());
console.log('Enumerator');
for (i in book) {
if (typeof(book[i]) != 'function') {
console.log(" " + book[i].firstname);
}
}
console.log('Apply');
var s = book.apply(function (b) {
return b.length();
});
console.log(" Length: " + s);
console.log('Apply with exception');
try {
var s = book.apply(function (b) {
throw { msg: "Error" };
});
console.log(" Length: " + s);
}
catch (e) {
console.log(" Exception caught: " + e.msg);
}
console.log('Anonymous function');
book.each(function (p) {
console.log(" " + p.lastname+", "+p.firstname)
});
console.log("Wrong arguments");
try {
book.add();
}
catch (e) {
console.log(" Error: " + e);
}
console.log("Lookup");
var p3 = book.lookup("Peter");
console.log(" Peter's last name is "+p3.lastname);
console.log("Deleting Peter");
delete book[0];
console.log(" " + book.length());