View Full Version : Object Oriented with event handler. Scope problem?

23 Nov 2007, 7:18 AM
I don't understand the behaviour and/or the logic behind these lines of code.

Here it's a working example:

function ClassWindow()
this.win = new Ext.Window({

//this.win.on('beforerender', this.myCustomHandler, this.win);
//this.win.on('beforerender', this.myCustomHandler, this);
this.win.on('beforerender', myCustomHandler, this);

function myCustomHandler()
//this.myCustomHandler= function()
Please, note the commented code.
These are combinations of what I've tried thinking they are good solutions.
I think the handler works also when I enable "this.win.on('beforerender', this.myCustomHandler, this.win);" or "this.win.on('beforerender', this.myCustomHandler, this);" in combination with "this.myCustomHandler= function()" (that is the commented lines).
Indeed, they don't work as expected, returning me an error.

Is it a pure Javascript OO issue? Or a misunderstand of how Ext works? Or simply a scope problem?

Thanks in advance

23 Nov 2007, 7:56 AM
It's likely a scope issue. Have you read anything from this thread (http://extjs.com/forum/showthread.php?t=6336) so that you understand scope.