<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                [TOC] # 函數 ## 1.申明函數 ### 1.1var申明函數 ~~~ var go = function(){ console.log("hello world"); } ~~~ ### 1.2function直接申明函數 ~~~ function go(){ console.log("hello world"); } ~~~ ### 1.3構造函數的方式申明函數(不推薦使用) ~~~ var go = new Function("a","console.log(a)"); ~~~ ## 2.構造函數的參數傳遞 > 在原型上定義一個方法,那么所有實例化的對象都共享這個方法 eg: ~~~ <script> function person(name,age){ this.dsjh = name;//自定義屬性 this.dsf = age;//自定義屬性 } /* 在原型上定義一個方法,那么所有實例化的對象都共享這個方法 */ person.prototype.sayname = function(){ console.log(this.dsjh); } var pi = new person("pikaqiu",20); pi.sayname(); </script> ~~~ > js對傳參不敏感 eg: ~~~ function go(a,b,c){ console.log(a); console.log(b); console.log(c); } go(1);//可以只傳遞一個參數 /* 函數的形參,是保存在函數對象的length屬性中 */ console.log(go.legth); ~~~ > 函數內部有個arguments對象,它用來存放函數傳入的參數,是一個類數組對象 eg: ~~~ function go(a,b,c){ console.log(a); console.log(arguments[0]); console.log(arguments[2]); console.log(arguments[3]); } go(1,2,3);//1 2 3 undefined ~~~ ## 3.重載 > 重載:函數根據傳入的參數不同,動態決定調用哪種方法 > js不支持從在,但可以使用argument對象去模擬重載 > eg: ~~~ function go(){ if(arguments.length == 1){ console.log(arguments[0]); }else if(arguments.length == 2){ console.log(arguments[0]+","+arguments[1]); } } go(1);//1 go(1,2);//1,2 go(1,2,3)//什么都沒有 ~~~ ## 4.函數數據類型 * 基本類型 string,number,boolean,null,undefined (變量 存儲位置:保存在棧區) * 引用類型 Function,Array,Object (函數,數組,對象 存儲位置:引用存放在棧區,實際對象保存在堆區) > js函數中,基本類型只傳值,應用類型既傳值,也傳地址 eg: ~~~ function go(){ console.log(1); } go.val = 2; var see = go; see.ind = 3; console.log(see.val);//2 console.log(go.ind);//3 ~~~ ## 5.this關鍵字的指向(bind、call、apply的區別) * call和apply都是對函數的直接調用,而bind方法返回的仍然是一個函數,因此后面還需要()來進行調用 * call(thisObj,params) apply(thisObj,[params]),這兩者的區別便在于調用時書寫方式不同 eg: ~~~ /* var wang = { name:"wangyu" } var cheng = function(){ console.log(this.name);// wangyu }.bind(wang); cheng(); */ var cheng = { name:"cheng", } var jiang = { name:"jiang", sayname(a,b){ console.log(this.name); console.log(a+b); } } jiang.sayname.call(cheng,1,2,3);// cheng 3 jiang.sayname.apply(cheng,[1,2]);// cheng 3 ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看