标签:prot ble 属性 asc val lse 不可 自身 lan
{
//对象属性遍历
let obj1 = { a: 1 }
let obj2 = { b1: 2 }
Object.defineProperty(obj2, "b2", {
enumerable: false,
value: 3
})
Object.setPrototypeOf(obj2, obj1)
let c = Symbol(‘c‘)
let d = Symbol(‘d‘)
//给obj2添加symbol属性
obj2[c] = 4
obj2[d] = 5
console.log(obj2)
//遍历出对象自身可枚举的属性名(不包含Symbol属性)
// for (let k of Object.keys(obj2)) {
// console.log("of1", k)
// }
//遍历出对象自身可枚举的属性值
// for (let v of Object.values(obj2)) {
// console.log(v)
// }
//遍历出对象自身可枚举属性的键值对数组
// for (let [k, v] of Object.entries(obj2)) {
// console.log(k, v)
// }
//getOwnPropertyDescriptor 获取一个对象自身属性的描述符
//包含Symbol属性、不可枚举的属性
//getOwnPropertyDescriptors
//获取一个对象的所有自身属性的描述符
//undefined
//let ret = Object.getOwnPropertyDescriptor(obj2, "a")
let ret = Object.getOwnPropertyDescriptor(obj2, c)
//let ret = Object.getOwnPropertyDescriptor(obj2, "b1")
//let ret = Object.getOwnPropertyDescriptor(obj2, "b2")
console.log(ret)
console.log(Object.getOwnPropertyDescriptors(obj2))
}
ES8 Oject.values、Object.entries、Object.getOwnPropertyDescriptors
标签:prot ble 属性 asc val lse 不可 自身 lan
原文地址:https://www.cnblogs.com/lceihen/p/14456021.html