Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save stableShip/6fb44972bf29ee45e57ab272bd9a3394 to your computer and use it in GitHub Desktop.
Save stableShip/6fb44972bf29ee45e57ab272bd9a3394 to your computer and use it in GitHub Desktop.
node 4.* 版本代码编写注意事项
## node 4.* 版本代码编写注意事项
### 'use strict'
node 4.× 支持let,const,class 都必须开启strict模式才能够使用,所以在代码的头部添加'use strict',开启strict模式
### class
class 示例:
```
'use strict';
class Point {
constructor(x, y) {
this.x = x;
this.y = y;
}
// 静态变量尚未实现
// static var a =1; // SyntaxError: Unexpected identifier
static distance(a, b) {
const dx = a.x - b.x;
const dy = a.y - b.y;
return Math.sqrt(dx*dx + dy*dy);
}
}
// 曲线实现静态变量定义
Point.a = 1;
const p1 = new Point(5, 5);
const p2 = new Point(10, 10);
console.log(Point.distance(p1, p2));
console.log(Point.a); // 1
```
public, private修饰还未实现,默认都是public的,可定义静态方法,但是静态变量还未实现
[参考资料](https://cnodejs.org/topic/56302801fa186b6f4496b53b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment