하이브리드 앱 센차터치 2.0 - 상속하기
개요
이미 정의되어 있는 부모 클래스의 기능을 그대로 물려받아 기능을 확장하므로써 작업 시간을 단축할 수 있다는 이점이 있다. 센차터치에서도 상속구현이 가능하다.
구현
// 첫번째 방법
Ext.define("MyObject", { //부모클래스 정의
name: null, age: null, loc: null,
setName: function( name ) { this.name = name; },
getName: function() { return this.name; },
setAge: function( age ) { this.age = age; },
getAge: function() { return this.age; },
setLoc: function( loc ) { this.loc = loc; },
getLoc: function() { return this.loc; }
});
Ext.define("MyObjectSub", { //자식 클래스 정의
extend: "MyObject",
tel: null,
setTel: functoin( tel ) {
this.tel = tel;
},
getTel: function() {
return this.tel;
}
});
var ref = Ext.create("MyObjectSub");
ref.setName( "홍길동" );
ref.setAge( 30 );
ref.setLoc( "서울 관악구 신림동" );
ref.setTel( "010" );
// 출력
console.log( "이름 : " + ref.getName() );
console.log( "나이 : " + ref.getAge() );
console.log( "위치 : " + ref.getLoc() );
console.log( "전화번호: " + ref.getTel() );
//두번째 방법 config( getter / setter )구조를 이용한 상속 구현
Ext.define("MemberSuper", { //부모 클래스 정의
constructor: function( config ) {
this.initConfig( config );
},
config: {
name: null, age: null, loc: null, tel: null, email: null
}
});
Ext.define("MemberSub", { //자식 클래스 정의
extend: "MemberSuper",
config: {
agree: null
}
});
var ref = Ext.create("MemberSub", {
name: "홍길동", age: "28", loc: "서울 불광동",
tel: "010", email: naver@naver.com, agree: "Yes"
});
//출력
console.log( "이름 : " + ref.getName() );
console.log( "나이: " + ref.getAge() );
console.log( "위치 : " + ref.getLoc() );
console.log( "전화번호 : " + ref.getTel() );
console.log( "이메일 : " + ref.getEmail() );
console.log( "수신여부 : " + ref.getAgree() );