LoginSignup
0
0

More than 5 years have passed since last update.

ポリマーでの参照型データのバインディング

Posted at

参照型による意図しないバインディング

参照型によって意図せずデータがバインディングされてしまうことが多々あったので検証メモ。

テスト

Step 0 (Polymer created)

  • o1 ⇄ object (2 way data biding via Polymer system)

  • o2 = o1 (参照型)

  • o3.name = o1.name (非参照型)

Step1 (ボタン1)

  • object.name = "newValue1"

Step2 (ボタン2)

  • object = { name: "newValue2" }

結果

Step 0 終了時

o1.nameo2.nameobject.name がbindingされている。
o2 が意図しないbinding(自分がjs知らなすぎるだけか)

Step 1 終了時

object.nameに参照型で ない ものを代入
o1.nameo2.nameobject.name のbindingは維持

Step 2 終了時

objectに参照型で ある ものを代入
o2 の意図しないbindingが意図せず解除

考察

参照型をバインディングする時はどの値を見にいっているか、いつ代入した注意。
(あたりまえか汗;;;)

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