zoukankan      html  css  js  c++  java
  • JavaScript 中的类方法,对象方法,Prototype方法

     1 <script type="text/javascript">
     2  function baseClass()
     3 {
     4     this.showMsg = function()
     5     {
     6         alert("baseClass::showMsg");   
     7     }
     8    
     9     this.baseShowMsg = function()
    10     {
    11         alert("baseClass::baseShowMsg");
    12     }
    13 }
    14 baseClass.showMsg = function()
    15 {
    16     alert("baseClass::showMsg static");
    17 }
    18 
    19 function extendClass()
    20 {
    21     this.showMsg =function ()
    22     {
    23         alert("extendClass::showMsg");
    24     }
    25 }
    26 extendClass.showMsg = function()
    27 {
    28     alert("extendClass::showMsg static")
    29 }
    30 
    31 extendClass.prototype = new baseClass();
    32 var instance = new extendClass();
    33 
    34 instance.showMsg(); //显示extendClass::showMsg
    35 instance.baseShowMsg(); //显示baseClass::baseShowMsg
    36 instance.showMsg(); //显示extendClass::showMsg
    37 
    38 baseClass.showMsg.call(instance);//显示baseClass::showMsg static
    39 
    40 var baseinstance = new baseClass();
    41 baseinstance.showMsg.call(instance);//显示baseClass::showMsg
    42 </script>
  • 相关阅读:
    zoj1137 poj1466
    poj3041
    zoj1455
    hdu1160 FatMouse's Speed
    zoj2770
    hdu1469
    hdu3169
    Mapped exception to response: 500 (Internal Server Error)
    Mapped exception to response: 500 (Internal Server Error)
    object is not a function
  • 原文地址:https://www.cnblogs.com/lvyongbo/p/4468173.html
Copyright © 2011-2022 走看看