Given a class like this
class Stuff {
set b(v) {
}
get c() {
return 'x'
}
}
const x = new Stuff
console.log(x.hasOwnProperty('b'))
how can I test for "properties" b and c, or list all such getter/setters? hasOwnProperty
does not show them to exist.
Just like all properties defined with method syntax (whether getter/setter or not), they’re on the prototype, not the instance, so call
hasOwnProperty
on the prototype: