代碼
提交代碼
class Calculate {
// 類的屬性
public x: number
public y: number
// 構(gòu)造函數(shù)
constructor(x: number, y: number) {
this.x = x
this.y = y
}
// 類的方法
add () {
return this.x + this.y
}
}
const calculate = new Calculate(1, 2)
console.log(calculate.add()) // 3
console.log(typeof Calculate) // 'function'
console.log(Calculate === Calculate.prototype.constructor) // true
運行結(jié)果