感谢群友popy32(740502708)分享
// @Author : popy32
// @Contact : 74o5o27o8#qq.com
// @File : ootest.aardio
// @Comment : 面向对象继承
// 父类抽象类
class Shape {
area = function(){}
perimeter = function(){}
}
// 子类实例化
class Rectangle {
ctor(length, width, ...) {
//调用父类的构造函数
this = ..Shape(...);
this.length = length;
this.width = width;
}
area = function(){
return this.length * this.width;
}
perimeter = function(){
return (this.length + this.width) * 2;
}
}
// 子类实例化
class Circle {
ctor(radius , ...) {
//调用父类的构造函数
this = ..Shape(...);
this.radius = radius ;
}
area = function(){
return this.radius * this.radius * ..math.pi;
}
perimeter = function(){
return 2 * this.radius * ..math.pi;;
}
}
if (owner == null) {
import console;
console.setTitle("面向对象测试");
console.log("单元测试(Unit Test)");
/*
创建类的实例,并调用类的方法
*/
var rectangle = Rectangle(10, 15);
var circle = Circle(12.5);
console.log("rectangle.area()", rectangle.area() );
console.log("rectangle.perimeter()", rectangle.perimeter() );
console.log("circle.area()", circle.area() );
console.log("circle.perimeter()", circle.perimeter() );
console.pause(true);
}