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

Your email will never ever be published.

Previous:
Use 'key' in React components to reset them February 12, 2025 React
Next:
Announcing: Spot the Difference February 23, 2025 React, JavaScript, Bun
Related by category:
How I run standalone Python in 2025 January 14, 2025 Python
Switching from Next.js to Vite + wouter July 28, 2023 JavaScript
How to SSG a Vite SPA April 26, 2025 JavaScript
An ideal pattern to combine React Router with TanStack Query November 18, 2024 JavaScript
Related by keyword:
Premailer 3.0.0 - classes kept by default June 7, 2016 Python, Web development
Newfound love of @staticmethod in Python July 2, 2012 Python
callable Python objects April 2, 2005 Python
Python new-style classes and the super() function July 12, 2008 Python