Ajax小結

          這個月工作比較忙,再加上讀了一本<javascript權威指南>,還有....所以沒有心上來寫blog,這個月最后一天了,趕上來補下作業,這個月主要研究了下ajax,其實對于ajax,年初興起的時候玩過一陣,也做過一些東東,當時的技術也處在異步調用,返回xml,更新網頁控件這個階段,半年過去了,Prototype.js,DWR,TrimPath JSTemplate等技術的成熟,使ajax更平民化,使我們更容易在自已的系統中使用.以下總結一下這個月學到的東東,同時與以前使用ajax進行對比.
          高級javascript總結
          1.函數也是對象

          var ?myDog? = ? {
          ????bark:?
          function () {
          ????????alert('Woof
          ! ');
          ????}

          }
          ;

          var ?myCat? = ? {
          ????meow:?
          function () {
          ????????alert('I?am?a?lazy?cat.?I?will?not?meow?
          for ?you.');
          ????}

          }
          ;
          ?
          function ?annoyThePet(petFunction) {
          ????
          // let's?see?what?the?pet?can?do
          ????petFunction();
          }


          // annoy?the?dog:
          annoyThePet(myDog.bark);
          // annoy?the?cat:
          annoyThePet(myCat.meow);
          2.數組,對象成員
          js中創建對象以及給對象動態創建成員
          var?obj?=?{};?//new,?empty?object
          obj['member_1']?=?'this?is?the?member?value';
          obj['flag_2']?
          =?false;
          obj['some_function']?
          =?function(){?/*?do?something?*/};
          以上代碼等同
          var?obj?=?{
          ????member_1:'
          this?is?the?member?value',
          ????flag_2:?
          false,
          ????some_function:?
          function(){?/*?do?something?*/}
          }
          ;
          ????
          obj.some_function();
          obj['some_function']();
          上面代碼表示在對象中使用成員,類似于hash表中使用一個key.
          3.在js中使用class
          //defining?a?new?class?called?Pet
          var?Pet?=?function(petName,?age){
          ????
          this.name?=?petName;
          ????
          this.age?=?age;
          }
          ;

          //let's?create?an?object?of?the?Pet?class
          var?famousDog?=?new?Pet('Santa\'s?Little?Helper',?15);
          alert('This?pet?is?called?'?
          +?famousDog.name);
          JS中類的繼承一般通過prototype屬性
          Pet.prototype.communicate?=?function(){?
          ????alert('I?
          do?not?know?what?I?should?say,?but?my?name?is?'?+?this.name);
          }
          ;
          用Prototype.js會簡單一些,prototype.js這個框架的代碼很值得一讀,里面用到了很多高級的JS技巧,巧妙的設計的許多優秀的設計方案.
          var?Pet?=?Class.create();
          Pet.prototype?
          =?{
          ????
          //our?'constructor'
          ????initialize:?function(petName,?age){
          ????????
          this.name?=?petName;
          ????????
          this.age?=?age;
          ????}
          ,
          ????
          ????communicate:?
          function(){
          ????????alert('I?
          do?not?know?what?I?should?say,?but?my?name?is?'?+?this.name);
          ????}

          }
          ;????
          ????????
          4.將函數作為參數,類似于ruby的閉包寫法
          var?myArray?=?['first',?'second',?'third'];
          myArray.each(?
          function(item,?index){
          ????alert('The?item?
          in?the?position?#'?+?index?+?'?is:'?+?item);
          }
          ?);

          posted on 2006-10-31 15:03 The One 閱讀(294) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2006年10月>
          24252627282930
          1234567
          891011121314
          15161718192021
          22232425262728
          2930311234

          導航

          統計

          常用鏈接

          留言簿(3)

          隨筆檔案(11)

          相冊

          我的郵箱

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 永福县| 常熟市| 柘荣县| 汤阴县| 晋中市| 射阳县| 康马县| 攀枝花市| 达日县| 雷山县| 临湘市| 乐昌市| 象州县| 永康市| 鸡东县| 安平县| 密云县| 会泽县| 渭南市| 漳平市| 昌吉市| 福清市| 财经| 上杭县| 尖扎县| 宁武县| 海阳市| 顺昌县| 凤冈县| 滦平县| 平度市| 驻马店市| 永仁县| 元江| 凉城县| 滦平县| 南投县| 天等县| 宁津县| 杭锦旗| 镇原县|