forked from winterbe/java8-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnashorn4.js
More file actions
52 lines (30 loc) · 702 Bytes
/
Copy pathnashorn4.js
File metadata and controls
52 lines (30 loc) · 702 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// function literal with no braces
function sqr(x) x * x;
print(sqr(3));
// for each
var array = [1, 2, 3, 4];
for each (var num in array) print(num);
// object literals in constructors
var runnable = new java.lang.Runnable() {
run: function() {
print('on the run');
}
};
runnable.run();
// bind properties
var o1 = {};
var o2 = { foo: 'bar'};
Object.bindProperties(o1, o2);
print(o1.foo);
o1.foo = 'BAM';
print(o2.foo);
// string trim
print(" hehe".trimLeft());
print("hehe ".trimRight() + "he");
// whereis
print(__FILE__, __LINE__, __DIR__);
// java import
var imports = new JavaImporter(java.util, java.io);
with (imports) {
var map = new HashMap();
}