<p>The inexistent ECMAScript 4 and ECMAScript 2015 took different paths. That's how you write a class in ES4 (similiar to Python (<code>def</code>), Rust (<code>fn</code>) and other languages):</p>
<pre class="lang-js prettyprint-override"><code>class C {
    function f(): void {
    }
}
</code></pre>
<p>That's ES2015:</p>
<pre class="lang-js prettyprint-override"><code>class C {
    f() {
    }
}
</code></pre>
<p>The former is a little verbose and the later is shorter. What are some advantages and disadvantages?</p>
<h2>Included Scripts</h2>
<p>Pro: if you've a directive for including a script into another (useful for partial implementations), it allows for an IDE to highlight the program correctly without the need of a LSP (although I don't even know whether LSPs are currently used for this).</p>
<p>E.g., in my language, VioletScript:</p>
<pre><code>class C {
    var x: Number = 10;

    include './foo.violet';
}
</code></pre>
<p>Another file, <code>foo.violet</code>:</p>
<pre><code>function f(): void {
    trace(this.x);
}
</code></pre>
<h2>Reserved words</h2>
<p>Depending on the language, certain words may be reserved if they reuse definitions. This is not the case for VioletScript:</p>
<pre><code>override // 'override' is an identifier
override function // 'override' is a modifier
private function // 'private' is a modifier
override final function // 'override' and 'final' are modifiers
</code></pre>
<p>It may the be different for other languages. So in my case there are no reserved word cons. Even <code>enum</code> and <code>type</code> work similiarly to the above and for TypeScript too.</p>

<syntax>
Pros and cons of reusing variable and function syntax on class block
CC BY-SA 4.0
2023-06-23T00:37:24.217Z
I don't understand why this was downvoted, it's an interesting question. That said, I believe in ES6's case, the decision to exclude the "function" keyword might have been related to the fact that the rest of the class syntax/semantics are very different between both proposals, so making "function" an error ensures that no one will accidentally use documentation from ES4.
kouta-kun
CC BY-SA 4.0
2023-06-23T10:02:19.113Z
@kouta-kun That might be a reason, since AS3 was still relevant I think (now it's not, so I guess no one cares.)
Hydroper
<h1>Deprecating old documentation/examples</h1>
<p>This goes particularly for ES2015 vs ES4, but a non-negligible amount of articles were written based on the ES4 class proposal before ES2015 came along (IIRC Flash's AS3 actually implemented it?), so if function definition was the same between both proposals there was a chance of people running into old tutorials and being confused by the different semantics (no this, typing hints/system, etc). This is especially an issue with a language like Javascript in which at the time of ES2015's release, development tooling was usually &quot;try it out in your browser and see if it works&quot;.</p>

CC BY-SA 4.0
2023-06-23T00:41:39.777Z
2023-06-23T00:41:39.777Z
kouta-kun
# Pros and cons of reusing variable and function syntax on class block
Posted by: username_0 on 2023-06-22
The inexistent ECMAScript 4 and ECMAScript 2015 took different paths. That's how you write a class in ES4 (similiar to Python (def), Rust (fn) and other languages):
class C {
    function f(): void {
    }
}

That's ES2015:
class C {
    f() {
    }
}

The former is a little verbose and the later is shorter. What are some advantages and disadvantages?
Included Scripts
Pro: if you've a directive for including a script into another (useful for partial implementations), it allows for an IDE to highlight the program correctly without the need of a LSP (although I don't even know whether LSPs are currently used for this).
E.g., in my language, VioletScript:
class C {
    var x: Number = 10;

    include './foo.violet';
}

Another file, foo.violet:
function f(): void {
    trace(this.x);
}

Reserved words
Depending on the language, certain words may be reserved if they reuse definitions. This is not the case for VioletScript:
override // 'override' is an identifier
override function // 'override' is a modifier
private function // 'private' is a modifier
override final function // 'override' and 'final' are modifiers

It may the be different for other languages. So in my case there are no reserved word cons. Even enum and type work similiarly to the above and for TypeScript too.
**Tags:** syntax
> **Comments:**
> **username_1**: I don't understand why this was downvoted, it's an interesting question. That said, I believe in ES6's case, the decision to exclude the "function" keyword might have been related to the fact that the rest of the class syntax/semantics are very different between both proposals, so making "function" an error ensures that no one will accidentally use documentation from ES4.  
> **username_0**: @kouta-kun That might be a reason, since AS3 was still relevant I think (now it's not, so I guess no one cares.)  
---
## 1 answers
### Answer by username_1 on 2023-06-23. Score: 4
# Deprecating old documentation/examples

This goes particularly for ES2015 vs ES4, but a non-negligible amount of articles were written based on the ES4 class proposal before ES2015 came along (IIRC Flash's AS3 actually implemented it?), so if function definition was the same between both proposals there was a chance of people running into old tutorials and being confused by the different semantics (no this, typing hints/system, etc). This is especially an issue with a language like Javascript in which at the time of ES2015's release, development tooling was usually "try it out in your browser and see if it works".
---
