Ajax小結(jié)

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

          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.數(shù)組,對(duì)象成員
          js中創(chuàng)建對(duì)象以及給對(duì)象動(dòng)態(tài)創(chuàng)建成員
          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']();
          上面代碼表示在對(duì)象中使用成員,類似于hash表中使用一個(gè)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會(huì)簡(jiǎn)單一些,prototype.js這個(gè)框架的代碼很值得一讀,里面用到了很多高級(jí)的JS技巧,巧妙的設(shè)計(jì)的許多優(yōu)秀的設(shè)計(jì)方案.
          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.將函數(shù)作為參數(shù),類似于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 閱讀(300) 評(píng)論(0)  編輯  收藏


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          <2006年10月>
          24252627282930
          1234567
          891011121314
          15161718192021
          22232425262728
          2930311234

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿(3)

          隨筆檔案(11)

          相冊(cè)

          我的郵箱

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 通海县| 房产| 勃利县| 江西省| 夏津县| 井陉县| 东阿县| 青铜峡市| 海原县| 拜泉县| 金山区| 上高县| 会同县| 扶绥县| 祁东县| 和平县| 南投市| 合山市| 彭泽县| 新绛县| 南木林县| 习水县| 康马县| 延寿县| 莎车县| 九龙坡区| 新建县| 静宁县| 德阳市| SHOW| 永州市| 盐池县| 哈尔滨市| 石门县| 白玉县| 游戏| 衡水市| 闽清县| 遂宁市| 湘潭市| 安乡县|