1 Ext.onReady(function () {
2 //extend 继承
3 Ext.define('Person', {
4 config: {
5 name: 'aaa'
6 },
7 //给当前定义的类加一个构造器 ,目的就是为了初始化信息
8 constructor: function (config) {
9 var me = this;//当前类对象
10 me.initConfig(me);// 真正的初始化传递进来的参数
11 }
12 });
13 Ext.define('Boy', {
14 extend: 'Person',
15 config: {
16 sex: '男',
17 age:20
18 }
19 });
20 var b = Ext.create('Boy', { //创建 boy类
21 name: '张数',
22 age:25
23 });
24
25 alert(b.name);
26 alert(b.sex);
27
28
29
30
31 //javascript :prototype(原型) 所有类的实例对象所共享
32 function Person(name) {
33 this.name = name;
34 this.sayName = sayName;
35 };
36 Person.prototype.sayName = function () {
37 alert(this.name);
38 }
39 var p1 = new Person('张三');
40 p1.sayName();
41
42 var p2 = new Person('李四');
43 p2.sayName();
44 alert(p1.sayName==p2.sayName); //true
45
46
47 //javascript : prototype(原型) :实现继承
48
49 //SupClass
50 var Person = function (name) {
51 this.name = name;
52 };
53 alert(Person.prototype.constructor);//原型对象的构造器,默认是当前类的模板
54 Person.prototype = {
55 constructor: Person,
56 id:100
57 };
58
59 //SubClass
60 var Boy = function (name,sex, age) {
61
62 //借用构造函数继承的方式。
63 Person.call(this,name);
64 this.sex = sex;
65 this.age = age;
66
67 };
68 //实现原型继承 :继承了父类的模板和父类的原型对象
69 Boy.prototype = new Person();
70 var b = new Boy('李四','男',23);
71 alert(b.name);
72 alert(b.sex);
73 alert(b.id);
74 });