使用 ExtJS 扩展类时的私有成员 [英] Private members when extending a class using ExtJS
本文介绍了使用 ExtJS 扩展类时的私有成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在ExtJS论坛上做了一些关于扩展类中的私有方法和字段的研究,我找不到任何真正的答案.
I have done some research on the ExtJS forum regarding private methods and fields inside a extended class, and I couldn't find any real answer to this.
当我说扩展课程时,我的意思是这样的:
And when I say an extended class I mean something like this:
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 的范围内添加一个新的变量 o 方法,该方法无法从外部访问但可以通过公共方法访问?
The problem here is that everything is public. So, how do I add a new variable o method within the scope of MyExtendedClass that cannot be accessed from outside but can be access by the public methods?
推荐答案
我使用类似下面的内容.
I use something like the following.
var toolbarClass = Ext.extend( Ext.Container,
{
/**
* constructor (public)
*/
constructor: function( config )
{
config = config || {};
// PRIVATE MEMBER DATA ========================================
var accountId = Ext.id( null, 'ls-accountDiv-');
// PUBLIC METHODS ========================================
this.somePublicMethod = function(){
console.log( accountId );
};
...
这篇关于使用 ExtJS 扩展类时的私有成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文