zoukankan      html  css  js  c++  java
  • js完美继承代码示例

     1 <!doctype html>
     2 <html lang="en">
     3 <head>
     4     <meta charset="UTF-8">
     5     <title>Document</title>
     6 </head>
     7 <body>
     8 <script>
     9     <!-- 定义继承函数-->
    10 var inherits = function(subType,superType){
    11     var F = function(){};
    12     F.prototype = superType.prototype;
    13     subType.prototype = new F();
    14     subType.prototype.constructor = subType;
    15 }
    16 //定义父元素
    17 function a(){
    18     this.q = 2;
    19 };
    20 a.prototype.cc="ert";
    21 //定义父元素;
    22 function b(){
    23 //a、 子元素内部调用call继承父元素的this的属性、方法
    24     a.call(this)
    25 };
    26 //b、 运行继承函数继承prototype的属性、方法;
    27 inherits(b,a);
    28 var c = new b();
    29     console.log(c.q)
    30 </script>
    31 </body>
    32 </html>
    坚持下去就能成功
  • 相关阅读:
    合并区间
    编程团体赛
    寻找数组的中间位置
    翻转链表2
    链表翻转
    CF1237H. Balanced Reversals
    arc108E
    agc028D
    CF1446D. Frequency Problem
    CF1439D. INOI Final Contests
  • 原文地址:https://www.cnblogs.com/suoking/p/4961584.html
Copyright © 2011-2022 走看看