-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What about let? #25
Comments
why the need of prefixing them at all? if going on this direction, why can't we reuse |
An important part of this design is emphasizing that "instance variables" are not properties. They differ from properties in many important ways and we believe that it is bad to lead JS programmers down a path where they don't fully understand all of those differences. One reason for choosing Note that the "hiddeness" of instance variables is only one of the many semantics differences between them and properties. Using Hidden methods are somewhat the opposite story. We have chosen to reuse the existing ConciseMethod syntax. The primary difference between regular concise methods and hidden concise methods is "hiddeness". So, in this case use of |
If you have concerns about conflating properties and fields, then I don't understand how it's acceptable to equate lexical variables (which don't belong to an object) to class instance variables (which do). |
Thanks for the explanation @allenwb - On your point here:
Why not use something like |
how about |
Actually, my second choice for a recycled keyword is class Foo { |
Both hidden methods and instance variables are not properties and both are hidden. (Or am I missing something?) Why do you consider "variableness" as a feature of instance variables but not as a feature of hidden methods? (I root for using the same keyword for both, whatever that keyword will be.) |
I keep thinking on what @ljharb said first, if we ever add initializers, at that time it could make sense to have consts (since we are gonna be able to define them), and if so, would it make more sense to let the door open for let (no pun intended 🙂) to be consistent with the way we are now defining variables? |
@futpib We considered using One of the issues with using Another factor, in one sense, the full equivalent state declaration should be:
|
Using either |
I think
Consider current mainstream ES6+ coding style prefer-no-(function)-var, it's a win-win to use About Note, I personally think About class A {
var x
->getX() {
return this->x
}
} This syntax is not very attractive in aesthetic point of view. Maybe we can consider class A {
var x
~getX() {
return this->x
}
}
The only dissatisfaction is |
I suggested class-parameters here as a way to be able to get data into Unrelated to the above but it could be the case that const externalName = 12
class MyClass {
// Not shared even with other instances
const fullyPrivate = 10
// Shared with other instances that have access to the ->sharedFoo
// token as
const sharedName = 10
->sharedFoo is sharedName
// Creates an anonymous variable that is attached to the current
// instance, would be pseudo-equivalent to
// const autoGenName
let ->x = 10
// In theory even external variables could work, e.g. for static properties
->someValue is externalName
} This would be very similar to private fields in that every object stores a mapping of private names --> values. But unlike private fields where |
I'm not sure what the outcome was at the recent TC39 meeting but I realised another couple bonuses of having a "closure sharing operator". First variables just work as variables: class Counter {
// localName is count
let count = 0
// shared name is ->internalCount
// just using a bad name to demonstrate it works
->internalCount is count
increment(i) {
count += i
}
// Combine two counters
combine(other) {
count += other->internalCount
}
getCount() {
return count
}
} Secondly they extend trivially to object literals with just a small syntax addition to object literals: function counter() {
let count = 0
return {
->internalCount is count,
increment(i) {
count += i
},
combine(other) {
count += other->internalCount
}
}
} There could of course be shorthands for this like: class Counter {
let ->count = 0
// Both count and this->count work
// if we make ->count declare both the variable
// and ->sharingOperator at once
increment(i) {
count += i
}
}
...
let count = 0
return {
->count,
increment() {
count += 1
}
}
... |
Currently, there's no reason to use
var
ever again (according to all JS styleguides I'm aware of) - it's expected to allowvar
inside class bodies, of course, but couldlet
also be allowed?(Obviously
const
wouldn't make sense unless there was an initializer)The text was updated successfully, but these errors were encountered: