Corsair

          My javaWorld
          數據加載中……
          關于學習javaScript基礎概念后寫的示例代碼
          < script >
          ?@1?函數定義
          function?method(){
          ????????????var?str="";
          ????????????for(var?i=1;i<arguments.length;i++){
          ????????????????????str+=arguments[i]
          ????????????????}
          ????????????alert(str);
          ????}
          method(1,2,3,4,5,6,7,8);
          ----------------

          @2?隨機函數
          var?method=new?Function("x","y","var?sum=0;sum=x+y;return?sum;");
          alert(method(1,2));
          ----------------

          @3?對象定義
          function?obj(){}
          var?obj1=new?obj();
          obj1.name="corsiar";
          obj1.age=22;
          function?method(x,y){
          ????????????return?x+y;
          ????}
          obj1.add=method;
          alert(obj1["name"]);
          alert(obj1.age);
          alert(obj1.add(1,2));
          ----------------

          @4?對象的定義2
          function?hero(name?,hp,mp){
          ????????????this.name=name;
          ????????????this.hp=hp;
          ????????????this.mp=mp;
          ????????????this.s1=show1;
          ????????????this.s2=show2;
          ????}
          function?show1(){
          ????????????alert(this.hp+100);
          ????}
          function?show2(){
          ????????????alert(this.mp+100);
          ????}
          var?corsair=new?hero("corsair",100,300);
          ????????alert(corsair.hp);
          ????????alert(corsair.mp);
          ????????corsair.s1();
          ????????corsair.s2();
          ?

          ?@5?關于對象中with(對象名){}和for(變量in對象名){}的用法;
          function?person(name,age,sex,tel){
          ????????????this.name=name;
          ????????????this.age=age;
          ????????????this.sex=sex;
          ????????????this.tel=tel;
          ????}
          function?show(){
          ????????????alert(this.name);
          ????????????alert(this.sex);
          ????????????alert(this.tel);
          ????}
          var?p1=new?person("corsair","22","boy","13778519215");
          with(p1){
          ????????????var?str="";
          ????????????str+=name+"?";
          ????????????str+=age+"?";
          ????????????str+=sex+"?";
          ????????????str+=tel+"?";
          ????}
          alert(str);
          var?tmp,temp="";
          for(tmp?in?p1){
          ????????temp+=p1;
          ????}
          alert(str);
          ?

          </script>

          posted on 2006-07-29 00:56 銀河海盜 閱讀(320) 評論(0)  編輯  收藏 所屬分類: WEB

          主站蜘蛛池模板: 吴川市| 漾濞| 丰镇市| 海安县| 安康市| 西和县| 乡宁县| 隆安县| 格尔木市| 平陆县| 富阳市| 开原市| 昆山市| 肃北| 红安县| 永嘉县| 金昌市| 济南市| 抚松县| 宝兴县| 平乡县| 丹巴县| 应用必备| 理塘县| 长宁区| 贡觉县| 大同县| 枣庄市| 广宁县| 原平市| 武夷山市| 历史| 鄂托克旗| 宜黄县| 赤壁市| 莱州市| 天台县| 方山县| 垣曲县| 正宁县| 宁明县|