I'm recently working on ES6 which I really enjoy.
The problem is that I experienced a really bad issue: I can't find a way to enumerate all my properties descriptors of a Class.
class A {
get property(){
return "the 'a' value";
}
}
const a = new A();
const b = {
get property() {
return "the 'b' value";
}
};
const objectKeys = (obj) => {
return Object.keys(obj).join(', ');
};
const objectPropertyNames = (obj) => {
return Object.getOwnPropertyNames(obj).join(', ');;
};
const objectForIn = (obj) => {
const result = [];
for(const prop in obj){
result.push(prop);
}
return result.join(', ');;
}
console.log(objectKeys(a)); // Output empty string
console.log(objectKeys(b)); // Output 'property'
console.log(objectPropertyNames(a)); // Output empty string
console.log(objectPropertyNames(b)); // Output 'property'
console.log(objectForIn(a)); // Output empty string
console.log(objectForIn(b)); // Output 'property'
console.log(a.hasOwnProperty("property")); // Output false
console.log(b.hasOwnProperty("property")); // Output true
console.log(Object.getOwnPropertyDescriptor(a, "property")); // Output undefined
console.log(Object.getOwnPropertyDescriptor(b, "property")); // Output a valid descriptor