Almost embarrassing that I didn't realize that it's the same thing!
class MyClass {
get something() {
}
}
is the same as Python's property
decorator:
class MyClass
@property
def something:
They both make an attribute on a class automatically "callable".
These two are doing the same functionality:
class Foo {
get greeting() {
return "hello";
}
place() {
return "world";
}
}
const f = new Foo();
console.log(f.greeting, f.place());
// prints 'hello world'
and
class Foo:
@property
def greeting(self):
return "hello"
def place(self):
return "world"
f = Foo()
print(f.greeting, f.place())
# prints 'hello word'
Comments