I have one doubt about javascript which I hope someone can explain me. I have a Watcher class which works just as expected:
function Watcher(paths) {
let watcher_instance = Object.create(Watcher.prototype);
watcher_instance.paths = paths;
return watcher_instance;
}
Watcher.prototype = {
init_watcher() {
console.log(this.paths)
}
}
Then, when I do
let watcher = new Watcher(paths);
watchers.init_watcher(); // prints the paths Array
all works as expected.
But I change the prototype to:
Watcher.prototype = {
init_watcher: () => {
console.log(this.paths) // prints undefined
}
}
this.path seems not to be initialized at all. Anybody knows why?
I've read this, but haven't seen any reference to this behaviour.