Circle类

by shitao1988

JavaScript

dojo.declare(
    "Shape", // 类名
null, // 无父类,使用null
{
    color: 0,
    setColor: function (color) {
        this.color = color;
    }
});

dojo.declare(
    "Circle",
Shape, {
    radius: 0,
    constructor: function (radius) {
        this.radius = radius || this.radius;
    },

    setRadius: function (radius) {
        this.radius = radius;
    },

    area: function () {
        return Math.PI * this.radius * this.radius;
    }
});


dojo.declare(
    "Rectangle",
Shape, {
    length: 0,
    width: 0,

    constructor: function (l, w) {
        this.length = l || this.length;
        this.width = w || this.width;
    },

    setLength: function (l) {
        this.length = l;
    },

    setWidth: function (w) {
        this.width = w;
    },

    area: function () {
        return this.length * this.width;
    }
});
var c = new Circle(5);
alert(c.area());
c.setColor(0x000FF);
alert(c.color);

var r=new Rectangle(3,4);
alert(r.area());