- Loading...
...
This Mozilla JavaScript 1.8 extension is also supported by Nashorn. This syntax allows braces and return keyword to be dropped when defining simple one-liner functions. See also https://developer.mozilla.org/en-US/docs/Web/JavaScript/New_in_JavaScript/1.8
Example:
| Code Block | ||
|---|---|---|
| ||
function sqr(x) x*x
// is equivalent to
// function sqr(x) { return x*x } |
...
This is another Mozilla JavaScript 1.6 extension supported by Nashorn. ECMAScript for..in iterates over property names or array indices of an object. for..each..in loop iterates over property values of an object rather than property names/indices. See also https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for_each...in
| Code Block | ||
|---|---|---|
| ||
for each (variable in object) { statement }
// print each array element
var arr = [ "hello", "world" ];
for each (a in arr) {
print(a)
}
|
...