zoukankan      html  css  js  c++  java
  • javascriptMVC框架面向对象编程

        //抽象形状类
        $.Class("Shape", {}, {
            //构造函数
            init : function(edge) {
                this.edge = edge;
            },
            //实例方法
            getEdge : function() {
                return this.edge;
            },
            //实例方法
            calcArea : function() {
                return -1;
            }
        });
        
        //三角形类
        Shape("Triangle", {}, {
            //构造函数
            init : function(bottom, height) {
                //调用父类同名方法
                this._super(3);
                this.bottom = bottom;
                this.height = height;
            },
            //重写方法
            calcArea : function() {
                return this.bottom * this.height / 2;
            }
        });
    
        //矩形类
        Shape("Rectangle", {}, {
            //构造函数
            init : function(bottom, height) {
                //调用父类同名方法
                this._super(4);
                this.bottom = bottom;
                this.height = height;
            },
            //重写方法
            calcArea : function() {
                return this.bottom * this.height;
            }
        });
    
        var triangle = new Triangle(4, 5);
        console.log(triangle.getEdge());
        console.log(triangle.calcArea());
    
        var rectangle = new Rectangle(4, 5);
        console.log(rectangle.getEdge());
        console.log(rectangle.calcArea());
  • 相关阅读:
    大小端模式
    深入理解c/c++ 内存对齐
    示波器使用
    C结构体
    51单片机内存问题
    S5PV210启动过程详解1
    程序中内存从哪里来
    再论typedef
    ARM体系结构总结
    MMU实验实验
  • 原文地址:https://www.cnblogs.com/zfc2201/p/3560424.html
Copyright © 2011-2022 走看看