Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

defineProperty #73

Open
Huauauaa opened this issue Mar 9, 2023 · 0 comments
Open

defineProperty #73

Huauauaa opened this issue Mar 9, 2023 · 0 comments
Labels

Comments

@Huauauaa
Copy link
Owner

Huauauaa commented Mar 9, 2023

for ...in ...可以把原型对象身上的属性遍历出来
Object.keys() 不能把原型对象身上的属性遍历出来

  1. 属性描述对象:
    JavaScript 提供了一个内部数据结构,用来描述对象的属性,控制它的行为,比如该属性是否可写、可遍历等等。
    这个内部数据结构称为“属性描述对象”(attributes object)

  2. 属性描述对象的6个元属性:

  • value:设置该属性的属性值,默认值为undefined
  • writable:表示能否修改属性的值,也就是说该属性是可写的还是只读的,默认为true(可写)
  • enumerable:表示改属性是否可遍历,默认为true(可遍历)
  • configurable:表示能否通过 delete 删除属性、能否修改属性的特性,或者将属性修改为访问器属性,默认为true(可配置)
  • get:get是一个函数,表示该属性的取值函数(getter),默认为undefined
  • set:get是一个函数,表示该属性的存值函数(setter),默认为undefined
  • configurable 如果设为false,将阻止某些操作改写该属性,比如无法删除该属性,也不得改变该属性的属性描述对象(value属性除外
@Huauauaa Huauauaa added the js label Mar 11, 2023
Huauauaa added a commit to Huauauaa/learn-mdn that referenced this issue Mar 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant