LoginSignup
0
1

More than 1 year has passed since last update.

【JavaScript】プロパティーとディスクリプター

Posted at

ディスクリプター

プロパティに対する設定値をディスクリプターという

ディスクリプターの種類

▼ ディスクリプター4種
value(値)
configurable(設定変更可能)
enumerable(列挙可能)
writable(値の変更可能)

このディスクリプターの値を設定することでプロパティのとる挙動を変更することができる

.js
const obj = {};

Object.defineProperty(obj, 'prop', {
       configurable: true,
       value: 0, // {props: 0} の状態になる
       writable: true // 値の変更が可能になる
});

obj.prop = 1; // writableがtrueであれば1を代入できる
delete obj.prop; // configurableがtrueであればdeleteできる

参考資料

0
1
1

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
1