<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>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                ### 概念:在定義函數、接口和類的時候,不預先指定類型,在使用的時候再指定類型的一種特性 ### 寫法:如:`fun<T>(arg : T)` 案例1:單個參數 ``` 定義一個方法,參數類型可選,T不是固定的,可以是任意的 function fun1<T>(arg : T):T{ return arg; } fun1<number>(111);//參數是數字 fun1<string>("111");//參數是字符串 ``` 案例2 : 多個泛型參數 ``` function fun2<T,U>(a:T,b:U){ console.log(a , b); } fun2<string,number>("hello",1); fun2<number[],string>([1,2,3],"hh"); ``` 案列3:返回對應參數的長度,前提條件:此參數的類型必須有這個屬性:如:string,array等類型 ``` //此時T沒有length這個屬性,所以需要繼承對應的類型,或者自定義一個接口 function fun3<T >(a : T){ console.log(a.length); } ``` ![](https://img.kancloud.cn/92/35/9235333fbd697f03f2ac1b48a1f5eb27_897x219.png) 解決方法:繼承對應類型的屬性(extends) ``` function fun3<T extends string | string[] | number[]>(a : T){ console.log(a.length); } fun3<string>("6666");//4 fun3<string[]>(["1","2"]);//2 fun3<number[]>([1,2,3]);//3 ``` 自定義一個接口,接口中有length這個屬性 ``` interface Ilength{ length : number } function fun4<T extends Ilength>(a : T){ console.log(a.length); } fun4([1,2,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>

                              哎呀哎呀视频在线观看