static/class properties
Andrew Fedoniouk
news at terrainformatica.com
Thu Sep 19 23:08:12 PDT 2013
On Thu, Sep 19, 2013 at 11:08 AM, Andrea Giammarchi
<andrea.giammarchi at gmail.com> wrote:
> the A.whatever is explicit to the class so it's the less ambiguous, IMO
>
> I see already confusing to understand if properties will be defined in the
> instance or in the class ... could not tell easily while I could, reading
> `A.VALUE = 10;` instead.
>
> Anyway, using that outside the class definition as:
>
> ```javascript
> class A {
> // do whatever in here ...
> // that you want inherited/assigned too
> }
> const A.VALUE = 10;
> ```
>
> is already good, if possible, and ambiguity free (but I cannot remember the
> `const obj.prop = value;` state)
>
> Hopefully in that way instances won't inherit a thing for sure ^_^
>
I did them this way:
class Foo {
this var instanceVar1 = 1;
this var instanceVar2 = 2;
var classVar1 = 3;
var classVar2 = 3;
}
'this var' can easily be parsed and will not break existing grammar.
In fact I do have [1] other "this thing" combinations:
"this function" - reference of current function inside the function.
Useful e.g. for recursive calls of anonymous functions.
"this super" - reference of 'this' of outer function.
"this super super ..." - the same as above but for outer this of outer, etc.
[1] http://www.codeproject.com/Articles/33662/TIScript-language-a-gentle-extension-of-JavaScript
--
Andrew Fedoniouk.
http://terrainformatica.com
More information about the es-discuss
mailing list