What is the best approach to iterate through private class fields?
class Person {
#isFoo = true;
#isBar = false;
constructor(first, last) {
this.firstName = first;
this.lastName = last;
}
enumerateSelf() {
console.log(this);
// (public/private fields shown)
// iterate through instance fields
for (let key in this) {
console.log(key)
// (only public fields shown)
}
// What is the technique to iterate/loop through private fields as well?
}
}
new Person('J', 'Doe').enumerateSelf();