PDA

View Full Version : function scope change.



fenuk
4 Dec 2010, 11:40 AM
i have this example:


Ext.onReady(function(){


new Ext.Window({

title : "Window",
height : 400,
width : 400,
items : new Ext.FormPanel({
labelWidth: 75,
frame:true,
title: 'Simple Form',
width: 350,
defaults: {width: 230},
defaultType: 'textfield',
items: [{
fieldLabel: 'First Name',
name: 'first'
}],
buttons: [{
text: 'Some function',
handler: function() { <!--function must close window--> }
}]
})
}).show()
})


what need do, that function close window?

Condor
4 Dec 2010, 11:56 AM
You could use:

handler: function(btn){
var win = btn.findParentByType('window');
win[win.closeAction]();
}

fenuk
4 Dec 2010, 12:34 PM
wow, first time see this:


win[win.closeAction]();


why not:

win.close()

what principle different?

Condor
5 Dec 2010, 12:05 AM
It's what the [x] button at the top does too.

fenuk
5 Dec 2010, 12:58 AM
do you have some other examples this syntax?

Condor
5 Dec 2010, 3:21 AM
A very common use is:

element[bool ? 'addClass' : 'removeClass'](someClass);