zoukankan      html  css  js  c++  java
  • 函数式继承示例

    <html>
    <head>
    <title></title>
    <script language="javascript" type="text/javascript">
    function print(msg){
      document.write(msg);      
    }
    
    function println(msg){
        print(msg + "<br/>");
    }
    //抽象类形状类
    function Shape(edges){
        var _edges = edges;
        
        var that = {
            getArea : function(){
                return -1;
            },
            getEdges : function(){
                return _edges;
            }
        };
        
        return that;
    }
    //三角形类
    function Triangle(bottom, height)
    {
        var that = Shape(3);
        
        var _bottom = bottom;
        var _height = height;
        //重写父类方法
        that.getArea = function(){
            return 0.5 * _bottom * _height;
        };
        
        return that;
    }
    //四边形类
    function Rectangle(bottom, height)
    {
        var that = Shape(4);
        
        var _bottom = bottom;
        var _height = height;
        //重写父类方法
        that.getArea = function(){
            return _bottom * _height;
        };
        
        return that;
    }
    </script>
    </head>
    
    <body>
    <script language="javascript" type="text/javascript">
    var triangle = Triangle(4, 5);
    println(triangle.getEdges());
    println(triangle.getArea());
    
    println("---------------------");
    
    var rectangle = Rectangle(4, 5);
    println(rectangle.getEdges());
    println(rectangle.getArea());
    </script>
    </body>
    </html>
  • 相关阅读:
    SQL Server 全文搜索 配置、查询初体验
    SQL Server 触发器
    SQL Server 锁
    SQL Server 事务语法
    SQL Server 表变量和临时表的区别
    SQL Server系统存储过程
    SQL 语句转换格式函数Cast、Convert
    SQL Server 系统视图
    T-SQL 批处理
    SQL Server 分区表
  • 原文地址:https://www.cnblogs.com/zfc2201/p/2758364.html
Copyright © 2011-2022 走看看