The ES6 class syntax does not change the functionality of Javascript at all. It is merely syntax sugar for prototype declarations. Once parsed, it just creates prototype objects which can then be used in an OO fashion the same way manually declared prototype objects have always been used in JS. So, the class syntax doesn't really change anything except make prototype definitions prettier to declare. The resulting objects are no more class-like than what people did manually in ES5.
Here's an example (run only in a browser that supports the ES6 class
syntax like Chrome as of Dec 2015).
// ES6 class syntax
class Polygon {
constructor(height, width) {
this.height = height;
this.width = width;
}
calcArea() {
return this.height * this.width;
}
get area() {
return this.calcArea()
}
}
// ES5 equivalent prototype syntax
function Poly(height, width) {
this.height = height;
this.width = width;
}
Object.defineProperties(Poly.prototype, {
calcArea: {
value: function () {
return this.height * this.width;
}
},
area: {
get: function () {
return this.calcArea();
}
}
});
var p1 = new Polygon(10, 20);
var p2 = new Poly(10, 20);
log(p1.area);
log(p2.area);
log(Object.getOwnPropertyNames(Object.getPrototypeOf(p1)));
log(Object.getOwnPropertyNames(Object.getPrototypeOf(p2)));
Output in Chrome as of Dec 2015:
200
200
["constructor","calcArea","area"]
["constructor","calcArea","area"]
Working jsFiddle: http://jsfiddle.net/jfriend00/92hhohdc/