bind(), call(), and apply()
Why is bind() necessary in the setTimeout call?
const counter = {
count: 0,
increment: function() {
this.count++;
}
};
const increment = counter.increment;
setTimeout(increment.bind(counter), 1000);
const counter = {
count: 0,
increment: function() {
this.count++;
}
};
const increment = counter.increment;
setTimeout(increment.bind(counter), 1000);