<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 功能強大 支持多語言、二開方便! 廣告
                [TOC] ### js中的“類“ ~~~ 1. js使用帶參帶參函數模擬java中的類(es5) 2. 也可以使用es6語法創建類 ~~~ demo1: ~~~ function Person(name, age) { this.name = name; this.age = age; this.eat = function () { console.log("吃飯"); } } ~~~ ### demo2(es6): ~~~ <script> // es6創建一個類 class Person { constructor(name, age) { this.name = name; this.age = age; } sayName() { console.log(this.name); } } let di = new Person("name", "age"); console.log(di) </script> ~~~ ### js中的繼承: ~~~ 1. js中每一個對象都有__proto__(雙下劃線屬性)實質上是個指針,指向上一級類或object,指向它的原型對象,同時共享原型上的方法 (當給它的原型上添加方法、屬性時 在對象中找改方法、屬性 找不到的情況下 通過__proto__找原型上的內容) 2. js中的繼承基于原型繼承 3. 獲取原型的所有方法 Object.getPrototypeOf(tong); ~~~ ### es5中js中實現屬性的繼承: ~~~ 1. 在不使用this關鍵字的時候(麻煩): <script> var Person = function (name, age) { this.name = name; this.age = age; } Person.prototype.see = function () { console.log(this.name + "愛看片") } function Teacher(skill) { //屬性繼承(實現在繼承的基礎上再添加新的屬性)(但是屬性這樣繼承很麻煩于是就出現了使用 .call(this,,)來繼承父類中的屬性) this.skill=skill; } var cheng = new Teacher(); cheng.name="tong"; cheng.age=18; cheng.skill="bb" console.log(cheng); </script> 2. 使用(較簡單): <script> var Person = function (name, age) { this.name = name; this.age = age; } Person.prototype.see = function () { console.log(this.name + "愛看片") } function Teacher(name,age,skill) { //屬性繼承(實現在繼承的基礎上再添加新的屬性)(但是屬性這樣繼承很麻煩于是就出現了使用 .call(this,,)來繼承父類中的屬性) Person.call(this,name,age);//相當于 this.name = name; this.age = age; this.skill=skill; } var tong=new Teacher("tong",18,"bb"); console.log(tong) //方法繼承 Teacher.prototype = new Person(); //繼承 Teacher.prototype.constructor = Teacher;// 要加上這句不加的話teacher的構造器指向的person 加上實現真正的繼承 console.log(Teacher.prototype.constructor); // var cheng = new Teacher(); // cheng.name="tong"; // cheng.age=18; // cheng.skill="bb" // console.log(cheng.name); </script> ~~~ ### es5中js中實現 方法 的繼承: ~~~ Teacher.prototype = new Person(); ~~~ ### es6中的繼承 (與java相通) ~~~ <script> class Person{ constructor(name,age){ this.name = name; this.age = age; } sayName(){ console.log(this.name); } } class Teacher extends Person{ constructor(name,age,skill){ super(name,age); this.skill = skill; } } var cheng = new Teacher("cheng",18,"pp"); cheng.sayName(); console.log(cheng.name); console.log(cheng); </script> ~~~
                  <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>

                              哎呀哎呀视频在线观看