我有这样的代码:
class Category {
constructor(
readonly _title: string,
) { }
get title() {
return this._title
}
}
type Categories = typeof categories
const categories = {
get pets() {
return new class extends Category {
constructor() {
super(
'Pets',
)
}
get dishes() {
return new Category(
'Pets dishes',
)
}
}
},
get cloth() {
return new class extends Category {
constructor() {
super(
'Cloth',
)
}
get accessories() {
return new Category(
'Accessories',
)
}
}
},
}
Object.entries(categories).forEach(([, category]) => {
// Actual logs:
// ["_title"]
// ["_title"]
// Expected logs:
// ["dishes"]
// ["accessories"]
console.log(Reflect.ownKeys(category))
})
为什么Reflect.ownKeys
返回的结果与我预期的不同?
如何获得获得者名单?