// *** before: ***
function Counter() {
this.count = 0;
setInterval(function () {
this.count++; // this внутри callback - не Counter
}, 1000);
}
var square = function (x) {
return x * x;
};
// *** in version ES2015: ***
function Counter() {
this.count = 0;
setInterval(() => {
this.count++; // стрелочная функция берёт this снаружи
}, 1000);
}
const square = x => x * x;
const add = (a, b) => a + b;