最近有機會對倉庫系統專案做Code review,網頁的寫法大多是用ExtJs(其實是用ExtNet) 所以買了一本書學習一下:

 下面程式碼主要是用Ext.extend 將Person繼承Object之後寫簡單的方法和屬性,

再給另一個Developer繼承Person重寫已存在的方法,真是有物件導向的精神, 希望能夠學好ExtJs啊~

<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);
   }
  }
 });

    var p = new Person('John', 'Smith');
    alert('Hi, ' + p.getName());

    var d = new Developer('John', 'Smith');
    d.isCoding = false;
    alert('Hi, ' + d.getName());
</script>
</body>
</html>

 

arrow
arrow
    文章標籤
    ExtJS
    全站熱搜

    黒森林蛋糕 發表在 痞客邦 留言(0) 人氣()