Consider this piece of code:
var states = {
"default" : {
foo: "foo",
mouseReleased: function() {
console.log("Mouse released");
this.foo = "bar";
}
}
}
var canvas = function(states) {
return {
states: states,
currentState: "default",
draw: function() {
if (this.states[this.currentState].mouseReleased != undefined) {
window.mouseReleased = this.states[this.currentState].mouseReleased
}
}
}
}
When I release the mouse, the console shows "Mouse released", but states.default.foo
does not change to bar
. Is there a way to not use window.mouseReleased
's this
? I've read a little bit about bind
, but I am not sure what it means. Am I searching in the right place?