Is there a convenience method in ES5 to determine whether a property is a getter or setter, or is the following idiomatic?
var o = {
get foo() { return 'foo'; },
set bar(value) {},
bam: 'bam',
};
function isGetterOrSetter(o, k) {
var descriptor = Object.getOwnPropertyDescriptor(o, k);
return !!(descriptor.get || descriptor.set);
}
isGetterOrSetter(o, 'foo'); // true
isGetterOrSetter(o, 'bar'); // true
isGetterOrSetter(o, 'bam'); // false