typescript/school/class_demo.ts · 477 字节 · 下载原文
// 类与方法 —— TypeScript 的面向对象外壳
// Classes and methods -- the TypeScript OO surface
//
// ⚠ 这是**能力边界判据**:本仓 JS 子集对 `new X().method()` 的支持情况直接反映在这里。
class Point {
x: number;
y: number;
constructor(x: number, y: number) {
this.x = x;
this.y = y;
}
sum(): number {
return this.x + this.y;
}
}
const p: Point = new Point(3, 4);
println_int(p.sum());