「JavaScript/演算子」の版間の差分

削除された内容 追加された内容
Ef3 (トーク | 投稿記録)
→‎分割代入: リファクタリング
タグ: 2017年版ソースエディター
Ef3 (トーク | 投稿記録)
→‎new演算子: クリーンアップ
タグ: 2017年版ソースエディター
672 行
 
=== new演算子の構文 ===
;構文:<syntaxhighlight lang="js"> new コンストラクタ [ ( [ パラメータ列 ] ) ]</syntaxhighlight>
;[https://paiza.io/projects/dWM8oB-5HTzZe7vbjg29Jw?language=javascript 例]:<syntaxhighlight lang="js">
 
'''例'''
<syntaxhighlight lang="js">
/*
* function 製のコンストラクタに適用した例
*/
const T = function(x = 0) {
this.x = x;
}
T.prototype.value = function() {
return this.x;
}
 
693 ⟶ 691行目:
*/
class C {
constructor(x = 0) {
this.x = x;
}
value() {
return this.x;
}
}
 
const c = new C(13);
console.log(c.value())
</syntaxhighlight lang="js">
;実行結果:<syntaxhighlight lang=text>
42
13
</syntaxhighlight>