Reflect.ownKeys和Object.keys
时间: 2023-10-19 20:25:28 浏览: 131
Reflect.ownKeys和Object.keys都是用来获取对象的属性键的方法,但它们之间有一些区别。
Reflect.ownKeys返回对象的所有属性,不管属性是否可枚举,包括普通属性和Symbol属性。它的返回值等效于Object.getOwnPropertyNames(target).concat(Object.getOwnPropertySymbols(target))。
而Object.keys只返回对象的可枚举属性的键。它的返回值是一个数组,包含了所有可枚举属性的键。
所以,如果你需要获取对象的所有属性键,不管可枚举与否,你可以使用Reflect.ownKeys方法。如果你只需要获取对象的可枚举属性键,你可以使用Object.keys方法。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [Reflect.ownKeys和Object.keys详解](https://blog.csdn.net/lin1072368472/article/details/108220371)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [Reflect.ownKeys()与Object.keys()区别 以及 JS中的可枚举属性与不可枚举属性](https://blog.csdn.net/happyqyt/article/details/90578205)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [reflect-own-keys-x:Reflect.ownKeys的伪造](https://download.csdn.net/download/weixin_42133329/16208967)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文