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

          主站蜘蛛池模板: 台前县| 博罗县| 安庆市| 广安市| 涟水县| 建阳市| 绥阳县| 思茅市| 潮州市| 六安市| 武乡县| 阿克苏市| 兴仁县| 武城县| 潞城市| 乡城县| 营口市| 新竹县| 亳州市| 高州市| 文化| 九江县| 清镇市| 军事| 隆化县| 南康市| 武穴市| 织金县| 罗平县| 玛纳斯县| 大连市| 东台市| 武宁县| 新干县| 三门县| 清流县| 蓝山县| 泗阳县| 新疆| 长岭县| 武川县|