📜  prototip - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:07.804000             🧑  作者: Mango

代码示例1
var circle = {
    radius: 5,
    create: function (radius) {
        var circle = Object.create(this);
        circle.radius = radius;
        return circle;
    },
    area: function () {
        var radius = this.radius;
        return Math.PI * radius * radius;
    },
    circumference: function () {
        return 2 * Math.PI * this.radius;
    }
};

var circle2 = circle.create(10);