#Object literal that has two functions that share an implementation?
7 messages · Page 1 of 1 (latest)
const x = {
a: () => 'a',
b() {
return this.a()
},
}
Not sure why you couldn't just do:
const fn = () => 'a'
const x = { a: fn, b: fn }
I could but I've wondered for a while if there was a more convenient way. I find it kind of annoying that I have to shift my focus outside the object when I'm trying to share code within it.
Eh, I mean if you want to reference something twice, that something has to have a name.
Whether that name is fn or this.a.
thanks @tidal thunder