In Javascript I have defined an object like this:
function myObject() {
this.x = 5;
window.addEventListener("resize", this.resizeHandler);
}
myObject.prototype.doSomething = function() {
alert(this.x);
}
myObject.prototype.resizeHandler = function() {
this.doSomething(); // Here occurs error.
}
var obj = new myObject();
However I am running into the error message:
"Uncaught TypeError: undefined is not a function".
Question is "why is that?" Explanation would be great!
thisin a function is generally based on how that function is invoked, you need to invoke it in such a way that you, implicitly or explicitly, "tell" the function what itsthisvalue should be.