0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

デフォルト引数が素敵【2020/11/20】

Posted at

javascriptでは、デフォルト引数が設定できる

ある条件がtrueの時だけ、モデルを呼び出して処理をしたい

  • メソッド側
model.method(data, true) 
model.method(data)
  • モデル側(model.js)
method(data, isHTML = false) {
    if(isHTML) {
      console.log(data)
    }
  }

とすれば、メソッド側でtrue/falseの分岐を一々書かなくても、必要なものにtrueを追加で引数に入れるだけで良い。
コードがシンプルになる。

参照: MDN-Docs

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?