zoukankan      html  css  js  c++  java
  • javascript类式继承模式#1——默认模式

     1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     2 <html xmlns="http://www.w3.org/1999/xhtml">
     3 <head>
     4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
     5 <title>类式继承模式#1——默认模式</title>
     6 </head>
     7 
     8 <body>
     9 <script type="text/javascript">
    10 
    11     function Parent(name){
    12         this.name=name||'Adam';
    13     };
    14     
    15     Parent.prototype.say=function(){
    16         return this.name;
    17     };
    18     
    19     function Child(name){};
    20     
    21     inherit(Child,Parent);
    22     
    23     function inherit(C,P){
    24         C.prototype=new P();        
    25     }
    26     
    27 /***************************************/
    28 
    29 var kid=new Child('Janking');
    30 
    31 console.log(kid.say())
    32 
    33 //缺点:inherit()并不支持将参数传递到子构造函数中,而子构造函数然后又将参数传递到父构造函数中。
    34 
    35 
    36 </script>
    37 </body>
    38 </html>
  • 相关阅读:
    扩展性很好的一个分页存储过程
    SQL中列转行
    Server.MapPath() 方法(摘自互联网)
    容易遗忘のSQL
    Linq读取XML
    字节流和字符流
    Java中" "和 ' '
    Spring常用基本注解
    finally和return
    JS 深度clone
  • 原文地址:https://www.cnblogs.com/w3develop/p/3434865.html
Copyright © 2011-2022 走看看