最近有機會對倉庫系統專案做Code review,網頁的寫法大多是用ExtJs(其實是用ExtNet) 所以買了一本書學習一下:
下面程式碼主要是用Ext.extend 將Person繼承Object之後寫簡單的方法和屬性,
再給另一個Developer繼承Person重寫已存在的方法,真是有物件導向的精神, 希望能夠學好ExtJs啊~
var p = new Person('John', 'Smith'); var d = new Developer('John', 'Smith'); <html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Ext中的繼承</title>
</head>
<script src="/shared/ext-base.js" type="text/javascript"></script>
<body>
<script type="text/javascript">
Person = Ext.extend(Object, {
constructor: function (first, last) {
this.firstName = first;
this.lastName = last;
}
, getName: function () {
return this.firstName + ' ' + this.lastName;
}
});
Developer = Ext.extend(Person, {
isCoding: true,
getName: function () {
if (this.isCoding) {
return '滾開';
} else {
return Developer.superclass.getName.call(this);
}
}
});
alert('Hi, ' + p.getName());
d.isCoding = false;
alert('Hi, ' + d.getName());
</script>
</body>
</html>
留言列表