PDA

View Full Version : What are advantages/disvantages of use me=this or Ext.bind defining function scope ?



American horizon
14 Sep 2017, 6:08 AM
Suppose i've a controller in which i've defined some functions, and one of this should be called when i click on a specific button, but in the while i will lose the desired contest/scope

Using me=this


Ext.define('CS.controller.MainPanel', {
extend: 'Ext.app.Controller',
id: "MainPanel",
init: function() {
this.control({
"importbtn": {
click: function(btn) {
...
var me=this;
fileInput.addEventListener('change', me.myFunc(), false);
}

}
})
},
myFunc: function(){}
})


Using Ext.bind



Ext.define('CS.controller.MainPanel', {
extend: 'Ext.app.Controller',
id: "MainPanel",
init: function() {
this.control({
"importbtn": {
click: function(btn)
{
...
var functionToCall= Ext.bind(
function(e)
{
this.myFunc())
},
this //scope
)

fileInput.addEventListener('change', functionToCall, false);
}
}
})
},
myFunc: function(){}
})


Which is the best way to do it and why?
Thanks