-
Notifications
You must be signed in to change notification settings - Fork 19
Why not use obj#prop instead obj.#prop ? #39
Comments
I don't see a big advantage here. The motivation for class X {
#y
z() {
w()
#y()
}
} Should that parse as |
you can not simply write sharp and property class X {
z() {
w()
this#y()
}
#y(){ }
} There is no ambiguity. Do not use their antiquated concepts to my decisions. I proposed a completely new semantics. It is clear that my decision suggests that the MY semantics rather than your obsolete. Here is the link to the description of my semantics #36 People dislike expansions that my decision is simply not able to recognize my genius and the genius of my decision. I feel that I need to write their own language and its compiler so that the world saw that I was right and was always right. I have already begun experiments https://www.npmjs.com/package/es-privates-loader |
or just double dot class Cat {
constructor(){
this..privateArr = []
}
..privateFunc(){
this..privateArr.push()
}
} |
|
What about |
I prefer the |
@littledan, is their any documentation on why the shorthand even exists? I'm not sure yet why private properties get a shorthand while public properties do not have a shorthand. Typing |
cc @wycats @dherman who are the staunchest champions of the shorthand. Even if the shorthand didn't exist, I kinda like the |
I just wanted to write down my basic thoughts in favor of the shorthand, especially since a number of people have raised questions recently. Firstly, I agree that the mental model of private state is extremely important, and wouldn't want to sacrifice clarity for "typing less". However, I believe that the shorthand syntax suggests a reasonable mental model, and also that the The Mental Model of the Shorthand Syntax
Notably, it is possible for a class to want to use its own public interface on purpose (for example, when calling methods or accessors that are intended to be overridable). For a class' own code, the distinction between "the outside interface" and "the inside interface" is important. People have argued that private state should have symmetry with Some have argued that the only way to plausibly understand Fundamentally, my opinion boils down to this: I think that " People have also raised problems like this to illustrate that class {
#name;
setup() {
document.body.onclick = function() { #print(); }
}
#print() {
console.log(#name);
}
} The argument is that it's not obvious, without the There's an alternative way to teach it, which is to say that "the inner function is no longer running in the same object". This is, in fact, somewhat important, because other constructs that aren't inherited into nested functions also don't contain In general, the way to avoid this kind of footgun is to use arrows, and a way to understand nested functions is "doesn't inherit anything that has to do with the current instance". Bottom line: I think that, especially with these new features, we will need a way of teaching classes that is natively about classes, and that the kinds of problems people are worried about here are really about the limits of stretching the ES5 mental model to an increasingly sophisticated class model. |
Dot accessor will mean public prop
obj.prop
Sharp accessor will mean private prop
obj#prop
Example:
Example 2:
Example 3:
The text was updated successfully, but these errors were encountered: