use the `function` keyword to declare getters
See original GitHub issueI think that if we decide to endorse #6424, it’ll be best to use the function
keyword to declare getters. It’s just way more regular:
function foo()() => "";
function bar() => "";
function baz => "";
and
function foo()()
{
return("");
}
function bar()
{
return("");
}
function baz
{
return("");
}
as opposed to
function foo()() => "";
function bar() => "";
value baz => "";
and
function foo()()
{
return("");
}
function bar()
{
return("");
}
value baz
{
return("");
}
You’d still be able to do everything you do today (i.e. refining variables with getter+setter and vice‐versa).
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:9 (9 by maintainers)
Top Results From Across the Web
getter - JavaScript - MDN Web Docs - Mozilla
The get syntax binds an object property to a function that will be called when that property is looked up.
Read more >JavaScript Getter and Setter (with Examples) - Programiz
In the above program, a getter method getName() is created to access the property of an object. ... Note: To create a getter...
Read more >Property getters and setters - The Modern JavaScript Tutorial
Accessor properties are represented by “getter” and “setter” methods. In an object literal they are denoted by get and set :.
Read more >Using Getters and Setters in Javascript - TekTutorialsHub
We use the Get keyword to declare a Getter method. The accessor function that assigns a value to a property is known as...
Read more >JavaScript getters and setters - JS Curious
The get keyword is used to create a getter function that will return a computed value. Unlike normal functions, we don't need to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Well I think @lucaswerkmeister already put it pretty well. A getter is not a function. Simple as that.
I would call that a “procedure”, perhaps. A function takes parameters, can return a result, and can have side effects. A value cannot take parameters, and if it has side effects that aren’t idempotent, you’re doing something wrong. Getters should not perform a task – they should get a value, and nothing else!
Ceylon also never just stores a value in a memory location. Even a non-lazy member, like just
shared Integer i = 1;
, always compiles to a getter (and, ifvariable
, a setter). This makes it possible to switch from eager to lazy values without breaking binary compatibility. Changing to a function, on the other hand, is a breaking change. The point is that, as a user, you don’t need to know if a value is eager, lazy, or a getter. You just use it, and trust that it’s implemented reasonably.Dunno. I feel like I’m just repeating myself, but this is really important: You shouldn’t think of getters like functions. You can do this, yes:
but that’s not what getters are supposed to do. As a user of your class, I expect that these are logically equivalent, though the first one may or may not be less efficient:
If you want to treat getters just like other functions, then I’d say the logical consequence would be to drop them altogether, in favor of functions, not to change their syntax. But then you lose an important and convenient language feature: the ability to define reasonable getters.