0

I noticed implements is a reserved keyword in JavaScript. However, I haven't come across any usage for that keyword. As a fact I know there's no concept of interfaces in JavaScript unlike other programming languages such as Java, which utilises implements keyword when implementing an interface. Although I researched about it, I couldn't find the exact reason why JavaScript has reserved this keyword.

So, my question is is there any reason why this keyword is reserved?

Isuru Perera
  • 351
  • 1
  • 3
  • 13
  • [This](https://stackoverflow.com/questions/38834625/whats-the-difference-between-extends-and-implements-in-typescript) might help. – Tibrogargan May 31 '22 at 18:35
  • @Tibrogargan TS !== JS – VLAZ May 31 '22 at 18:36
  • 1
    https://webplatform.github.io/docs/javascript/future_reserved_words/ – Martheen May 31 '22 at 18:36
  • @VLAZ except that Typescript compiles to JS, and luckily enough the JS designers had reserved words already in the language they could use to make comprehension easier. – Tibrogargan May 31 '22 at 18:38
  • 1
    @Tibrogargan So, the reason JS reserved the keywords solely for TS (released 17 years later) to use them? That doesn't really track, given that TS *could* have used many other ways to designate "implements". No need for a specific keyword, given that symbols can be used, just how `const foo: number` leverages `:` instead of a keyword. Moreover, even if `implements` wasn't reserved, it could still be used because positionally in `class A implements B` it is not ambiguous. The same way how `as` is not a reserved word in JS yet is still has special meaning in TS. – VLAZ May 31 '22 at 18:45
  • @VLAZ You're coming at it from the wrong angle. The TS designers saw the reserved word was there and used it. JS designers probably planed to use it for something similar, so they reserved the word. EEE. The concept is what's important - which is why I linked it. Whether or not the TS concept and the planned JS concept are identical is open for debate. – Tibrogargan May 31 '22 at 18:53
  • @Tibrogargan question is why did JS reserve the keywords. You suggested that TS is relevant to this. So, it's not me who is coming at it from the wrong direction. Hence why it isn't really useful to suggest it as it is *not* the reason JS reserved `implements`. And as I said, TS neither needed to use it, nor would have been a big problem if it wasn't reserved. The whole TS angle is a red herring. – VLAZ May 31 '22 at 18:56
  • @VLAZ the `implements` concept that the JS designers planned is probably similar to the one the `TS` designers implemented. It's a reserved word in JS because it's **planned**. It's a keyword in TS because EEE. – Tibrogargan May 31 '22 at 19:02

1 Answers1

1

implements is a Future Reserved Word which means it's a keyword, but currently doesn't have a meaning in the language.

The following words are used as keywords in proposed extensions and are therefore reserved to allow for the possibility of future adoption of those extensions.

The following tokens are also considered to be FutureReservedWords when they occur within strict mode code (see 10.1.1).

implements  let      private    public  yield
interface   package  protected  static    

This list is different in the latest ECMAScript Language Specification since let, yield, and static have received a formal meaning since.

The current Reserved Word section:

enum is not currently used as a keyword in this specification. It is a future reserved word, set aside for use as a keyword in future language extensions.

Similarly, implements, interface, package, private, protected, and public are future reserved words in strict mode code.


I don't see how the implements keyword would refer to anything other than inheritance which suggests to me that technical committee 39 (the body formally responsible for the ECMAScript specification) hasn't ruled out the possibility of adding isolation/inheritance.

The process for getting a feature added includes an input phase. IDL for ECMAScript is an example of input that might come to shape this feature.

This repository is intended for an investigation into using an Interface Description Language (IDL) in the ECMAScript standard. It is not currently at a stage in TC39.

D M
  • 5,769
  • 4
  • 12
  • 27