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>
  • 相关阅读:
    结对编程(阶段二)
    结对编程 第一阶段
    Git实验
    webpack02
    webpack01
    实验五 单元测试
    实验四 代码审评
    UML建模工具的安装和使用
    实验二 结对编程(阶段二)
    博客园背景的修改
  • 原文地址:https://www.cnblogs.com/lvyongbo/p/4468173.html
Copyright © 2011-2022 走看看