#In a class, is there a way to make a class property accessible to methods without `this.`?

1 messages · Page 1 of 1 (latest)

scarlet otterBOT
#
bawdyinkslinger#0

Preview:```ts
class Foo {
bar: string = "hi"
baz: number = 4

meth() {
console.log(bar) // I wish I didn't have to say this.bar
console.log(baz) // I wish I didn't have to say this.baz
}
}```

shy sigil
#

I'm aware I can say const bar = this.bar as the first line of the method

#

but it's annoying to do that in every method

#

I think it works this way in Java as long as there isn't a name collision

stiff radish
#

There's no reasonable way to avoid this. AFAIK.

shy sigil