PDA

View Full Version : how can i use the scope function of object?



koffdsa
12 Oct 2007, 7:57 AM
hi all:
there is a problem of scope in my codes,i don't know how can i do.Do somebody give me some clues?thanks
use the Ext windows demo to show my question.
this code is from window.js

Example.TabWindow = Ext.extend(Ext.app.Module, {
init : function(){
this.launcher = {
text: 'Tab Window',
iconCls:'tabs',
handler : this.createWindow,
scope: this
}
},

createWindow : function(){
/*do something*/
}
});

then in Desktop.js file i add a function in desktop function Ext.desktop
the item is a object as Example.TabWindow.

this.addDeskBtn = function(item){
var div = document.createElement('div');
div.id="ux-desktop-"+item.text;
desktopEl.dom.appendChild(div);
Ext.apply(this.app,item);
var deskBtn = new Ext.Button({
text:item.text,
renderTo:div.id,
iconCls:item.iconCls,
handler:item.createWindow
});
}
everything goes well,no error,and a button than i wanted show up in the desktop,but when i click the button,no event happend,i think it's maybe some wrong in the handler:item.createWindow by error scope.but item.text or item.iconCls has the values.
wait for your replay.
espermier