function Foo() {
var _bar = 42;
return {
get bar() {
return _bar;
}
}
}
var foo = Foo();
foo.bar
/*
42
*/
However the fact that you can transparently replace a simple property by a computed one (e.g. for backwards compatibility or to trigger side effects in observables) does make explicit, Java-style, getters and setters less useful. something(
"Template string {thing}"
.format(thing=33)
) # square even numbers
range(11)
.filter(lambda x: not x % 2)
.map(lambda x: x ** 2)
However such a chaining API is not practical in python, because lambda syntax is voluntarily crippled to one expression only.
Thanks for this great website !