What event gets fired when a variable's value changes?

We can define a function to perform everytime an attribute’s value gets changed by using this.on("attr:someAttrName"), function(value, prev) { ...});

But I want to do this for a variable that belongs to the script. By that I mean, I created the variable using this.someVar. How do I define a function to trigger whenever a variable’s value changes?


You can do it like this:

MyScript.prototype.initialize = function(){
   this.on('attr:speed', this.myMethod);

// and add this method to your script
MyScript.prototype.myMethod = function(value, prev){