jjs 可以调用js nashorn engine
位置:jdk1.8.0_271\bin\jjs.exe
jjs --language=es5 -strict=true 注意options
jjs --language=es6
交互
在es5下,使用es6语法中的let,报错
直接执行脚本
jjs --language=es5 -strict=true test.js
test.js
var array1 = new Array();
array1[0] = 'aaa';
array1[1] = 'bbb';
array1[2] = 'ccc';
var temp = array1.shift();
print(temp);
let str1 = 'abc123';
print(str1);
分别使用es5 es6 运行脚本
参考:
https://docs.oracle.com/javase/8/docs/technotes/tools/unix/jjs.html
http://openjdk.java.net/projects/nashorn/