<script>
// 继承
function Shape(name){
this.name = name;
}
function circle(name,radiu){
Shape.call(this,name);
this.radiu = radiu;
}
circle.prototype = new Shape();
circle.prototype.constructor = circle;
circle.prototype.computeArea = function(){
console.log("圆的面积:" + this.radiu * this.radiu * Math.PI);
}
let c1 = new circle('圆形1',2);
console.log(c1);
c1.computeArea();
</script>
JavaScript 实现继承 —— { }
最新推荐文章于 2022-02-06 18:09:56 发布