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

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                [TOC] ****** ## 1 Class的意義 1. js語言傳統方法通過構造函數,定義生成新對象, ~~~ function Point(x,y){ this.x = x; this.y = y; } Point.prototype.toString = function () { return '(' + this.x + ', ' + this.y + ')'; } ~~~ 2. ES6提供了Class語法糖,來簡化對象的創建。通過Class關鍵字,可以定義類。 ~~~ //定義類 class Point { constructor(x, y) { this.x = x; this.y = y; } toString() { return '(' + this.x + ', ' + this.y + ')'; } ~~~ 3. ES6的類,完全可以看做構造函數的另一種寫法 ~~~ ;類的數據類型是函數,類本身指向構造函數 class Point{ // ... } typeof Point // "function" Point === Point.prototype.constructor // true ;構造函數的prototype屬性,在ES6的類上面繼續存在。類的所有方法都定義在類的prototype屬性上面 class Point { constructor(){ // ... } toString(){ // ... } toValue(){ // ... } } // 等同于 Point.prototype = { toString(){}, toValue(){} } ;在類的實例上調用方法,其實就是調用原型上的方法 class B {} let b = new B(); b.constructor === B.prototype.constructor // true ;類的方法都定義在prototype屬性上面,類的新方法可以添加在prototype上面。Object.assign可以很方便一次向類添加多個方法,而prototype對象的constructor屬性,直接指向類的本身。類的內部定義的所有方法,都是不可枚舉的,這一點與ES5的行為不一致。 ~~~ class Point { constructor(){ // ... } } Object.assign(Point.prototype, { toString(){}, toValue(){} }) Point.prototype.constructor === Point // true class Point { constructor(x, y) { // ... } toString() { // ... } } Object.keys(Point.prototype) // [] Object.getOwnPropertyNames(Point.prototype) // ["constructor","toString"] ~~~ ## 2 constructor方法 1. constructor方法是類的默認方法,通過new命令生成對象實例時,自動調用該方法,一個類必須有constructor方法,沒有顯示定義,空的constructor方法會被默認添加 ## 3 創建實例對象 ## 4 Class的繼承 ## 5
                  <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>

                              哎呀哎呀视频在线观看