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

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ~~~ /* * 面向對象:類的繼承封裝和多態 * [封裝] * 把實現一個功能的JS代碼進行封裝,主要目的:“低耦合高內聚” * * [多態] * 重載:方法名相同,參數的個數或者類型不同,此時名字相同的方法叫做方法的重載(后臺語言中的重載),JS中不存在重載的 * 重寫:子類重寫父類的方法 * * [繼承] * 子類繼承父類的屬性和方法 * 1. 原型繼承 * 2. call繼承 * 3. 寄生組合繼承 * 4. ES6中class類實現繼承 * ... */ // public void fn(int n,int m){ // // } // public void fn(string n,string m){ // // } // public void fn(int n,int m,int z){ // // } // //=>根據傳遞參數的不同執行不同的方法 // function fn(n, m) { // // } // // function fn(n, m, x) { // //=>后面的方法會把前面的方法覆蓋掉,不管傳遞多少實參,執行的都是后面的這個方法(JS中的重載指的是:同一個方法根據傳參不一樣,實現不同的功能) // } // // fn(10, 20); // fn(10, 20, 30); //=>原型繼承:讓子類的原型指向父類的一個實例 // function A() { // this.x = 100; // } // A.prototype = { // constructor: A, // getX: function () { // console.log(this.x); // } // }; // function B() { // this.y = 200; // } // B.prototype = new A(); // let f = new B(); //=>CALL繼承:把父類A做為普通函數執行,讓A中的THIS變為B的實例,相當于給B的實例增加一些屬性和方法(弊端:把父類A當做普通函數執行,和父類原型沒啥關系了,僅僅是把A中的私有屬性變為子類B實例的私有屬性而已,A原型上的公有屬性方法和B及它的實例沒啥關系) //new A() 把A作為類創建它的實例 this:實例 //A() 把A作為普通函數執行 this:window // function A() { // //=>this:f // this.x = 100; //=>f.x=100 // } // A.prototype = { // constructor: A, // getX: function () { // console.log(this.x); // } // }; // function B() { // //=>this:f // A.call(this);//=>call繼承 把A執行,讓A中的this變為f // this.y = 200; // } // let f = new B(); //=>寄生組合繼承:A的私有變為B的私有,A的公有變為B的公有 // function A() { // this.x = 100; // } // A.prototype = { // constructor: A, // getX: function () { // console.log(this.x); // } // }; // function B() { // A.call(this);//=>基于CALL把A的私有變為B的私有 f.x=100 // this.y = 200; // } // // B.prototype = A.prototype; //=>一般都不這樣處理,因為這種模式可以輕易修改父類A原型上的東西(重寫“太方便”了),這樣會導致A的其它實例也受到影響 // B.prototype=Object.create(A.prototype); // let f = new B(); /* * Object.create:內置Object類天生自帶的方法 * 1.創建一個空對象 * 2.讓新創建的空對象的__proto__指向第一個傳遞進來的對象(把OBJ作為新創建空對象的原型) */ // let obj={ // name:'哈哈' // }; // console.log(Object.create(obj)); //=>ES6中的類和繼承 //1.ES6中創建類是有自己標準語法的(這種語法創建出來的類只能NEW執行,不能當做普通函數執行) // class Fn {//=>Fn是類名,沒有小括號 // constructor(n, m) { // //=>等價于傳統ES5類的構造體 // this.x = n; // this.y = m; // } // // //=>給Fn的原型上設置方法(只能設置方法不能設置屬性) // getX() { // console.log(this.x); // } // // //=>把Fn當做一個普通對象設置的私有方法(和實例沒有關系),同樣也只能設置方法不能寫屬性 // static AA(){ // // } // } // // Fn.prototype.BB = 100; // // Fn.xxx = 'xxx'; // let f = new Fn(10, 20); // function Fn(n,m){ // this.x=n; // this.y=m; // } // Fn.prototype.getX=function(){} // Fn.prototype.BB=100; // Fn.AA=function(){} //=>把Fn當做一個普通對象設置的私有方法(和實例沒關系) class A { constructor() { this.x = 100; } getX() { console.log(this.x); } } class B extends A {//=>extends類似于實現了原型繼承 constructor() { super();//=>類似于CALL繼承:在這里SUPER相當于把A的CONSTRUCTOR給執行了,并且讓方法中的THIS是B的實例,SUPER當中傳遞的實參都是在給A的CONSTRUCTOR傳遞 this.y = 200; } getY() { console.log(this.y); } } let f = new B(); ~~~ ![](https://img.kancloud.cn/a4/bf/a4bf90a702d7fd132703f42cf7a014b9_2706x996.png) ![](https://img.kancloud.cn/1f/b6/1fb68a1f0e99e27bd363f844309115a5_2264x866.png)
                  <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>

                              哎呀哎呀视频在线观看