在我当前的项目中,我使用的是 ExtJs3.3。
我创建了许多具有私有变量和函数的类。例如:
MyPanel = function(config){
config = config || {};
var bar = 'bar';//private variable
function getBar(){//public function
return bar;
}
function foo(){
//private function
}
Ext.apply(config, {
title: 'Panel',
layout: 'border',
id: 'myPanel',
closable: 'true',
items: []
});
MyPanel.superclass.constructor.call(this, config);
};
Ext.extend(MyPanel , Ext.Panel, {
bar: getBar
});
Ext.reg('MyPanel', MyPanel);
我知道ExtJs4中新的做事方式是使用Ext.define
方法。所以我上面的代码看起来像这样:
Ext.define('MyPanel', {
extend: 'Ext.panel.Panel',
title: 'Panel',
layout: 'border',
closable: true,
constructor: function(config) {
this.callParent(arguments);
},
});
所以我想知道的是如何在 ExtJs4 中定义私有变量和函数,就像我在 ExtJs3 中所做的那样?
换句话说,我知道该Ext.define
方法将负责定义、扩展和注册我的新类,但是我应该在哪里声明var
不是类本身的属性但类需要的 javascript 。
MyPanel = function(config){
//In my Ext3.3 examples I was able to declare any javascript functions and vars here.
//In what way should I accomplish this in ExtJs4.
var store = new Ext.data.Store();
function foo(){
}
MyPanel.superclass.constructor.call(this, config);
};