3 ms·
No, just not commonly used; getters and setters aren't terribly useful in a language that allows such easy direct modification of objects (as opposed to say Jav
by RobertKerans 9y ago
No, just not commonly used; getters and setters aren't terribly useful in a language that allows such easy direct modification of objects (as opposed to say Java)
- Symen 9y agoBut transparent getters and setters can be used to emulate private or immutable properties: 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.