I have an es6 class 'Snake' in snake.js
I have an index.js
index.js instantiates a 'Snake'
index.js calls snake.move(dir)
I get an error this.isProperDir is not a function
snake.js
isProperDir(dir) {
dir = dir.toLowerCase();
var arr = ['left', 'up', 'down', 'right'];
return arr.includes(dir);
}
move(dir) {
console.log('a2: ' + this);
console.log('d: ' + this.isProperDir(dir));
}
index.js
window.setInterval(snake.move, 1000);
This gets printed to console:
a2: [object Window]
Uncaught TypeError: this.isProperDir is not a function
I just want to call that function inside my es6 class, I figure writing this
would refer to the function inside that class, but it seems to instead throw errors.