ECMAScript6 is a wonderful language that approaches the syntactic readability of python. If you're stuck with ECMAScript5 sure, go ahead and say javascript is terrible because it is. But ECMAScript6? No way. They fixed so many annoying things. the fat arrow that captures "this", proper classes and inheritance, maps and sets and string template literals are the biggest ones that jump to mind. es6 is to javascript like what c++11 is to c++ -- it made it so you don't have to use the warts. ECMAScript6 snippet:
class Shape {
constructor (id, x, y) {
this.id = id
this.move(x, y)
}
move (x, y) {
this.x = x
this.y = y
}
fixed_offset(off_x,off_y) {
return () => {
console.log(`offsets x: ${off_x} y: ${off_y}`)
return [this.x + off_x, this.y + off_y]
};
}
}
And yes ECMAScript5 is gross:
var Shape = function (id, x, y) {
this.id = id;
this.move(x, y);
};
Shape.prototype.move = function (x, y) {
this.x = x;
this.y = y;
};
Shape.prototype.fixed_offset(off_x,off_y) {
var self = this;
return function() {
console.log("offsets x: " + off_x + " y: " + off_y`)
return [self.x + off_x, self.y + off_y]
}
}