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:
A Python dict that can report which keys you did not use June 12, 2025 Python
In Python, you have to specify the type and not rely on inference October 10, 2025 Python
Native connection pooling in Django 5 with PostgreSQL June 25, 2025 Python
Combining Django signals with in-memory LRU cache August 9, 2025 Python
Related by keyword:
Newfound love of @staticmethod in Python July 2, 2012 Python
Premailer 3.0.0 - classes kept by default June 7, 2016 Python, Web development
callable Python objects April 2, 2005 Python
Python new-style classes and the super() function July 12, 2008 Python