mattajlsm
11 May 2007, 6:13 AM
Hello,
I'm new to Ext and not so old with Javascript...
I defined a button with Ext.Button. When the user click on the button, I want it to call a method of an object class instance.
Well let say something like this :
this is my Class
function MyTestClass(property) {
this.property=property;
}
MyTestClass.prototype.myMethod=function(){
alert(this.property);
}
I instance a new object from this Class :
var objTest = new MyTestClass('hello');
and then make the button :
var button1 = new Ext.Button($('button1'),{
text:'bouton1',
handler:objTest.myMethod,
});
(assuming there's a div in the body with id="button1")
Well I thought clicking on the button will alert "hello", but it doesn't :
"undefined" is alerted instead.
It actually comes from "this" in myMethod which doesn't refers to objTest but to the button object itself ...
Maybe I miss something about Javascript or Ext...
Any Idea how I can get this work ?
Thanks,
Matt
I'm new to Ext and not so old with Javascript...
I defined a button with Ext.Button. When the user click on the button, I want it to call a method of an object class instance.
Well let say something like this :
this is my Class
function MyTestClass(property) {
this.property=property;
}
MyTestClass.prototype.myMethod=function(){
alert(this.property);
}
I instance a new object from this Class :
var objTest = new MyTestClass('hello');
and then make the button :
var button1 = new Ext.Button($('button1'),{
text:'bouton1',
handler:objTest.myMethod,
});
(assuming there's a div in the body with id="button1")
Well I thought clicking on the button will alert "hello", but it doesn't :
"undefined" is alerted instead.
It actually comes from "this" in myMethod which doesn't refers to objTest but to the button object itself ...
Maybe I miss something about Javascript or Ext...
Any Idea how I can get this work ?
Thanks,
Matt