4
$\begingroup$

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.

$\endgroup$
2
  • 1
    $\begingroup$ 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. $\endgroup$
    – kouta-kun
    Jun 23, 2023 at 0:37
  • 1
    $\begingroup$ @kouta-kun That might be a reason, since AS3 was still relevant I think (now it's not, so I guess no one cares.) $\endgroup$
    – Hydroper
    Jun 23, 2023 at 10:02

1 Answer 1

4
$\begingroup$

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".

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .