zoukankan      html  css  js  c++  java
  • js模拟类的创建以及继承

    <html>

    <body>

        <script>
        //js模拟类的创建以及继承
        
        //第一步:创建父类
            function Parent(name){
                this.name = name;
            }
            //给父类添加属性方法
            Parent.prototype.age = 18;
            //var p1 = new Parent();
        //第二步:创建子类    
            function Child(){
                Parent.call(this,"asdfasfd");
                
            }
            
            //第三步:确定继承的关系
            
            Child.prototype = Object.create(Parent.prototype);
            
            Child.prototype.stuno = "2000";
            
            //第四步:改造构造器(不是很重要)
            //改变了某个构造器的原型之后,紧接着的代码一定是改构造器
            Child.prototype.constructor = Child;
            /* Object.create的实现
            function create(proto){
                function F(){
                
                
                }
                F.prototype = proto;
                var temp = new F();
                return temp;
            }
            
            */
            //var o = new Parent();
            //o instanceof Object;
            
            
            //constructor
            
            
        </script>
    </body>

    </html>

  • 相关阅读:
    病毒分裂(分治)
    【CQYZ-vijos】P1333 舞伴的搭配(贪心算法)
    算法系列之图--拓扑排序
    算法系列之图--DFS
    算法系列之图--BFS
    python读取txt里的json文件,存到excel,例子2
    python读取txt里的json文件,存到excel,例子1
    python读取excel数据做分类统计
    python datetime中timedelta的用法
    bootstrap用法小计
  • 原文地址:https://www.cnblogs.com/luowenjun-kio/p/7899962.html
Copyright © 2011-2022 走看看