<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>理解Ext.extend</title>
<link rel="stylesheet" href="src/ext/resources/css/ext-all.css"> <!--ext-base 必须在ext-all之前引入-->
<script src="src/ext/ext-base.js"></script>
<script src="src/ext/ext-all.js"></script>
<!--<script src="src/ext/ext-lang-zh_CN.js"></script>-->
<style> </style>
</head>
<body> <script>
Ext.onReady(function () {
// 基类Persion, 继承自Object
Person = Ext.extend(Object, {
constructor: function (first, last) {
this.firstName = first;
this.lastName = last;
},
getName: function () {
return this.firstName + '' + this.lastName;
},
}); // 继承Person 得到Developerde的子类
Developer = Ext.extend(Person, {
// 重写了getName()方法
getName: function () {
if (this.isCoding) {
return 'Go Away!';
} else {
// 访问父类的方法
return Developer.superclass.getName.call(this)
} },
}); // 检测是否成功继承
var p = new Person('John', 'Smith');
alert('Hi,'+ p.getName() + '欢迎来学习Ext')
});
</script>
</body>
</html>