このクラスがあるとしましょう(列挙型のように使用しています):
class Color {
static get Red() {
return 0;
}
static get Black() {
return 1;
}
}
Object.keys
get に似たものはあります['Red', 'Black']
か?
Node.js v6.5.0 を使用しているため、一部の機能が欠落している可能性があります。
このクラスがあるとしましょう(列挙型のように使用しています):
class Color {
static get Red() {
return 0;
}
static get Black() {
return 1;
}
}
Object.keys
get に似たものはあります['Red', 'Black']
か?
Node.js v6.5.0 を使用しているため、一部の機能が欠落している可能性があります。
結果を使用Object.getOwnPropertyDescriptors()
およびフィルタリングして、getter を持つプロパティのみを含めます。
class Color {
static get Red() {
return 0;
}
static get Black() {
return 1;
}
}
const getters = Object.entries(Object.getOwnPropertyDescriptors(Color))
.filter(([key, descriptor]) => typeof descriptor.get === 'function')
.map(([key]) => key)
console.log(getters)
Node.js 6.5.0 でも機能するはずです。
class Color {
static get Red() {
return 0;
}
static get Black() {
return 1;
}
}
const getters = Object.getOwnPropertyNames(Color)
.map(key => [key, Object.getOwnPropertyDescriptor(Color, key)])
.filter(([key, descriptor]) => typeof descriptor.get === 'function')
.map(([key]) => key)
console.log(getters)