zoukankan      html  css  js  c++  java
  • javascript类式继承模式#3——借用和设置原型

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>类式继承模式#3——借用和设置原型</title>
    </head>
    
    <body>
    <script type="text/javascript">
    
        function Parent(name){
            this.name=name||'Adam';
        };
        
        Parent.prototype.say=function(){
            console.log(this.name);
        };
        
        function Child(name){
            Parent.apply(this,arguments);
        };
        
        Child.prototype=new Parent();
        
        
        
    /***************************************/
    
    var kid=new Child('Janking');
    
    console.log(kid.name);
    kid.say();
    
    //缺点:父构造函数被调用了两次,因此导致了其效率低下的问题,最后,自身的属性会被继承两次。
    
    
    </script>
    </body>
    </html>
  • 相关阅读:
    day37 事务
    小组分享
    day36 pymysql 索引
    day 35 多表查询
    day 35 作业
    day 34 作业
    AST 节点类型对照表
    babel _shallowEqual.default
    js Proxy
    Symbol
  • 原文地址:https://www.cnblogs.com/w3develop/p/3434871.html
Copyright © 2011-2022 走看看