forked from winterbe/java8-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnashorn2.js
More file actions
35 lines (28 loc) · 787 Bytes
/
nashorn2.js
File metadata and controls
35 lines (28 loc) · 787 Bytes
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
var Nashorn2 = Java.type('com.winterbe.java8.samples.nashorn.Nashorn2');
var result = Nashorn2.fun('John Doe');
print('\n' + result);
Nashorn2.fun2(123);
Nashorn2.fun2(49.99);
Nashorn2.fun2(true);
Nashorn2.fun2("hi there")
Nashorn2.fun2(String("bam"))
Nashorn2.fun2(new Number(23));
Nashorn2.fun2(new Date());
Nashorn2.fun2(new RegExp());
Nashorn2.fun2({foo: 'bar'});
print('passing object hash:');
Nashorn2.fun3({
foo: 'bar',
bar: 'foo'
});
print('passing custom person object:');
function Person(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
this.getFullName = function() {
return this.firstName + " " + this.lastName;
}
}
var person1 = new Person("Peter", "Parker");
Nashorn2.fun3(person1);
Nashorn2.fun4(person1);