Ok, I am new to JS OOP, so bare with me.
The code is quite large so I will summaries and simplify, to show the piece that isn't working.
Ok I have defined a class and then an object with several methods.I call these:
theclass, theclass.method 1 and theclass.method 2.
Now what I want to do is from inside method1, I want to register an event handler for say "window" to run method2 on the current object.
Heres some code, and if I haven't explained something clearly, please ask questions.
Problem is it is not using "this" as the current object, so the browser thinks the method is invalid. I have tried putting this into a variable and passing that, this also does not work.
Please don't say the event listener wont work with ie6/other browsers, thats not important as this stage.
Thanks heaps in advance, Josh
The code is quite large so I will summaries and simplify, to show the piece that isn't working.
Ok I have defined a class and then an object with several methods.I call these:
theclass, theclass.method 1 and theclass.method 2.
Now what I want to do is from inside method1, I want to register an event handler for say "window" to run method2 on the current object.
Heres some code, and if I haven't explained something clearly, please ask questions.
Code:
theobj = new theclass();
theobj.method1();
function theclass(){
// whatever goes here
}
theclass.prototype.method1(){
window.addEventListener
?window.addEventListener('resize',[B]this.method2[/B],false)
:attachEvent('onresize',[B]this.method2[/B]);
}
theclass.prototype.method2(){
// do lots of stuff
}
Please don't say the event listener wont work with ie6/other browsers, thats not important as this stage.
Thanks heaps in advance, Josh
Comment