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

测试EXTJS4中的特性:config, extend, statics, mixins

2014-05-15 22:27 155 查看
Ext.onReady(function() {

alert("测试 config");

//测试 config

//构造一台智能手机

Ext.define('SmartPhone', {

config: {

hasTouchScreen: false,//有触摸屏

operatingSystem: 'Other',//操作系统

price: 500//价格

},

constructor: function(cfg) {

this.initConfig(cfg);

}

});

//iPhone手机

var iPhone = new SmartPhone({

hasTouchScreen: true,

operatingSystem: 'iOS'

});

alert( iPhone.getOperatingSystem());

alert(iPhone.getHasTouchScreen());

//Ext.Msg.alert('iPhone.getPrice():', iPhone.getPrice());

alert("测试 extend");

//测试 extend

//构造人类

Ext.define('Person', {

say: function(text) { alert(text); }//具有说的方法

});

Ext.define('Developer', {

extend: 'Person',//继承人类

say: function(text) { this.callParent(["print "+text]); }//继承了说的方法

});

var develop = new Developer();

develop.say("text");

alert("测试 static");

//测试 static

//构造一台计算机

Ext.define('Computer', {

statics: {

factory: function(brand) {

alert(brand);

}

},

constructor: function() { }//构造函数

});

//创建一台戴尔电脑

var dellComputer = Computer.factory('Dell');

alert("测试 mixins");

//测试 mixins

//唱歌

Ext.define('CanSing', {

sing: function() {

alert("sing()")

}

});

//音乐家

Ext.define('Musician', {

mixins: ['CanSing']

});

var m = new Musician();

m.sing();

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