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

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                >[success] # 命名空間 ~~~ 1.命名空間一個最明確的目的就是解決重名問題。本質上來說也是針對模塊化,使用的是對象的形式解決 模塊化讓其各自獨立不互相影響 ~~~ >[danger] ##### namespace 使用 ~~~ 1.通過第二個案例可以看出如果不'export ' 導出的話是轉譯后是不會變成對象屬性 ~~~ ~~~ namespace Shapes { export namespace Polygons { export class Triangle {} export class Squaire {} } } namespace Shapes1 { const a = 1 } namespace Shapes2 { export const a = 1 } ~~~ * 'npx tsc --outDir dist' 編譯后結果 ~~~ var Shapes; (function (Shapes) { var Polygons; (function (Polygons) { var Triangle = /** @class */ (function () { function Triangle() { } return Triangle; }()); Polygons.Triangle = Triangle; var Squaire = /** @class */ (function () { function Squaire() { } return Squaire; }()); Polygons.Squaire = Squaire; })(Polygons = Shapes.Polygons || (Shapes.Polygons = {})); })(Shapes || (Shapes = {})); var Shapes1; (function (Shapes1) { var a = 1; })(Shapes1 || (Shapes1 = {})); var Shapes2; (function (Shapes2) { Shapes2.a = 1; })(Shapes2 || (Shapes2 = {})); ~~~ >[danger] ##### 導出命名空間的內容 ~~~ 1.導出話使用'///' 后面接著'<reference path="地址"/> ' 舉個例子:/// <reference path="地址"/> ~~~ ~~~ // index.ts namespace Shapes { export namespace Polygons { export class Triangle {} export class Squaire {} } } namespace Shapes1 { const a = 1 } namespace Shapes2 { export const a = 1 } // index1.ts /// <reference path="./index.ts"/> Shapes2 ~~~ * 打包后使用指令npx tsc --outFile dist/a.js src/index1.ts ~~~ 1.將整個'index.ts' 文件定義變量全部導入 ~~~ ![](https://img.kancloud.cn/a3/5e/a35e8fc0131ae1959edcb41fcf04b9c2_882x702.png) >[info] ## 命名空間的用處 ~~~ 1.命名空間在現代TS開發中的重要性并不高,主要原因是ES6引入了模塊系統,文件即模塊的方式使得開發者能更好的得組織代 碼,但是命名空間并非一無是處,通常在一些非 TypeScript 原生代碼的 .d.ts 文件中使用,主要是由于 ES Module 過于靜態, 對 JavaScript 代碼結構的表達能力有限。 因此在正常的TS項目開發過程中并不建議用命名空間 ~~~
                  <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>

                              哎呀哎呀视频在线观看