2016-08-23 Modern JavaScript - Class 1. 世界是属于对象的。2. REF:: 世界是属于对象的。所有接触的语言都是面向对象的。遇到 js 这种异类,基于 prototype 原型链继承,就崩溃了。 123456789101112131415161718192021222324252627282930class Circle { constructor(radius) { this.radius = radius; Circle.circlesMade++; }; static draw(circle, canvas) { // Canvas绘制代码 }; static get circlesMade() { return !this._count ? 0 : this._count; }; static set circlesMade(val) { this._count = val; }; area() { return Math.pow(this.radius, 2) * Math.PI; }; get radius() { return this._radius; }; set radius(radius) { if (!Number.isInteger(radius)) throw new Error("圆的半径必须为整数。"); this._radius = radius; };} REF:: http://www.infoq.com/cn/articles/es6-in-depth-classes 下一篇 RESTful Status in Deep 上一篇 Modern JavaScript - Iterator (for...of)