「JavaScript/クラス」の版間の差分

削除された内容 追加された内容
Ef3 (トーク | 投稿記録)
→‎アクセサプロパティ: https://paiza.io/projects/BUjHE0rSBTH_IUDobE_s9g?language=javascript
タグ: 2017年版ソースエディター
Ef3 (トーク | 投稿記録)
タグ: 2017年版ソースエディター
211 行
return Object.assign(this, { real, imag })
}
Object.assign(Complex.prototype.toString, ={
function toString() { return `${this.real}+${this.imag}i` },
Complex.prototype.cadd = function cadd(n) { return new Complex(this.real + n.real, this.imag + n.imag) },
Complex.prototype.csub = function csub(n) { return new Complex(this.real - n.real, this.imag - n.imag) },
})
let a = new Complex(1, 1)
let b = new Complex(2, 3)