您的位置:首页 > Web前端 > JavaScript

Extjs4 类定义创建和特性

2012-11-11 21:54 155 查看
//类的声明其实就是一个fuction
function user(){
this.name='uspcat';
this.age=26; //var 就相当于高级语言中的private
var email="dd163.com";
this.getEmail=function(){
return email;
} }

//1 js创建一个对象 var u=new user();
//alert(u.name);
//alert(u.getEmail())

//2 js创建一个对象
var person={ name:'yfc', age:26 };
//alert(person.name+" "+person['age'])
*/
(function() {

// 声明一个命名空间
Ext.Loader.setConfig({
enabled : true,
paths : {
myApp : 'extstudy/ux'
}

});
Ext.onReady(function() {/*
* var win = new Ext.window.Window({ title :
* 'Hello', height : 200, width : 400
*
* }); // win.show(); //
* 1.得到按钮的dom对象;2.为按钮添加单击事件。3.单击时调用win的show方法
*
* Ext.get("myb").on("click", function() {
* win.show(); });
*
*/
// 1. 创建一个函数对象,用一个别名创建一个对象
var o = {
say : function() {
// alert(111);
}
}

var fn = Ext.Function.alias(o, 'say');
fn();

// 2创建一对象4.0提倡使用create创建对象
/*
* var win = Ext.create('Ext.window.Window', {
* width : 400,
* height : 300,
* title : 'uspcat' });
* win.show();
*/

// 3.自定义一个类,( 类之间的继承)
/*
* Ext.define("myWin",{
* extend:'Ext.window.Window',
* width:400,
* height:300,
* title:'uspcast',
* newtitle:'new uspcat',
* mySetTitle:function(){
* this.title=this.newtitle;
* },
* initComponent:function(){
* this.mySetTitle();
* this.callParent(arguments);
* }
*
* });
*/
// 实例化一个类对象
Ext.get('myb').on("click", function() {
var win = Ext.create("ux.mywin", {
title : 'my win',
price : 600,
requires : ['ux.mywin']
// 是否异步加载ux底下mywin.js
});
alert(win.getPrice());

});

Ext.define("say", {

cansay : function() {
alert("hello");
}
});

Ext.define("sing", {

sing : function() {
alert("sing hello111");
}
});

Ext.define('user', {

mixins : {// 混合对象,其实就是类直接的调用,实现类的多继承,在extjs中
say : 'say',
sing : 'sing'

}
});

var u = Ext.create("user", {});
u.cansay();
u.sing();

});

})();

mywin.js

Ext.define("ux.mywin", {
extend : 'Ext.window.Window',
width : 400,
height : 300,
config:{
hashTouchScreen:false,
operationSystem:'other',
price:50
},
title : 'ucast',
newtitle : 'new uspcat',
mySetTitle : function() {
this.title = this.newtitle;
},
initComponent : function() {
this.mySetTitle();
this.callParent(arguments);
}

});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐