// *** before: ***
function Counter() {
this.count = 0;
setInterval(function () {
this.count++; // this inside the callback is not Counter
}, 1000);
}
var square = function (x) {
return x * x;
};
// *** in version ES2015: ***
function Counter() {
this.count = 0;
setInterval(() => {
this.count++; // an arrow function takes this from the outside
}, 1000);
}
const square = x => x * x;
const add = (a, b) => a + b;