01.
class
Point
extends
Base {
02.
03.
constructor(x,y) {
04.
05.
super();
06.
07.
this[px] = x, this[py] = y;
08.
09.
this.r =
function
() {
return
Math.sqrt(x*x + y*y); }
10.
11.
}
12.
13.
get x() {
return
this[px]; }
14.
15.
get y() {
return
this[py]; }
16.
17.
proto_r() {
return
Math.sqrt(this[px] * this[px] +
18.
19.
this[py] * this[py]); }
20.
21.
equals(p) {
return
this[px] === p[px] &&
22.
23.
this[py] === p[py]; }
24.
25.
}
01.
let a = Map();
02.
03.
{
04.
05.
let k = Symbol();
06.
07.
a.set(k,
'value'
);
08.
09.
// 这里你可以访问和设置'value',比如a.get(k)。
10.
11.
}
12.
13.
//这里不行,k是不可见的。
01.
module math {
02.
03.
export
function
sum(x, y) {
04.
05.
return
x + y;
06.
07.
}
08.
09.
export
var
pi = 3.141593;
10.
11.
}
12.
13.
14.
15.
import {sum, pi} from math;
16.
17.
alert(sum(pi,pi));
01.
// 多行字符串
02.
03.
re`line1: (words )*
04.
05.
line2: \w+`
06.
07.
08.
09.
// It desugars to:
10.
11.
re({raw:
'line1: (words )*\nline2: \w+'
,
12.
13.
cooked:
'line1: (words )*\nline2: \w+'
})