我在ExtJS论坛上做了一些关于扩展类中的私有方法和字段的研究,但是我没有找到任何真正的答案。
当我说一个扩展类时,我的意思是像这样的东西:
Ext.ux.MyExtendedClass = Ext.extend(Ext.util.Observable, {
publicVar1: 'Variable visible from outside this class',
constructor: function(config) { this.addEvents("fired"); this.listeners = config.listeners; }, // to show that I need to use the base class
publicMethod1: function() { return 'Method which can be called form everywhere'; },
publicMethod2: function() { return this.publicMethod1() + ' and ' + this.publicVar1; } // to show how to access the members from inside another member
});
这里的问题在于所有东西都是公开的。那么,我如何在MyExtendedClass的范围内添加一个新变量或方法,使其无法从外部访问但可以被公共方法访问?
new
关键字不会影响此模块模式的成员,它们在执行Ext.extend时就已经被解析(早于构造函数或任何其他方法出现)。此外,模块模式是单例模式,我认为这也可以解释。 - Mariano Desanze