ejyoo's 개발 노트

정적속성 본문

FrontEnd/Ext

정적속성

ejyoovV 2021. 10. 6. 20:43

정적속성은 생성된 모든 객체가 공유하며 클래스의 인스턴스 명, 정적속성 방식 또는 statics()를 이용하여 사용한다.

자바에서 static과 동일하다

 

* 기본 형태

statics:{
  속성,
  메소드
}

 

* 예제 :

* 결과

2

2

-----------end

Ext.onReady(function(){
  Ext.define('CountTest',{
    config:{
      name:null
    },
    constructor:function(config){
      this.initConfig(config);
    }
  });
  Ext.define('extendsCountTest',{
    extend:'CountTest',
    statics:{
      count:0
    },
    addCount:function(){
      this.statics().count++;
    },
    getCount:function(){
      return this.statics().count;
    }
  });
  var test1 = Ext.create('extendsCountTest',{
    name:'test1'
  });
  test1.addCount();
  var test2 = Ext.create('extendsCountTest',{
    name:'test2'
  });
  test2.addCount();
  
  document.write(test1.getCount() + "<br>");
  document.write(test2.getCount() + "<br>");
});

'FrontEnd > Ext' 카테고리의 다른 글

참고 사이트 목록  (0) 2021.11.30
싱글톤  (0) 2021.10.06
config 속성  (0) 2021.10.05
상속  (0) 2021.10.05
생성자 초기화  (0) 2021.10.05