How do we enumerate through private class fields?
class Person {
#isFoo = true;
#isBar = false;
constructor(first, last) {
this.firstName = first;
this.lastName = last;
}
enumerateSelf() {
console.log(this);
// (pub/priv fields shown)
// enumerate through instance fields
for (let key in this) {
console.log(key)
// (only public fields shown)
}
// How do we enumerate/loop through private fields too?
}
}
new Person('J', 'Doe').enumerateSelf();
Object.getOwnPropertyDescriptors
will help but I've not played around with private properties much. Last time I looked at them, they weren't finalised. – HabaneraObject.*
– Bearing