Propose simpler string constant

Alican Çubukçuoğlu alicancubukcuoglu at gmail.com
Wed Dec 16 14:41:21 UTC 2015


How are enums declared?
```javascript
let myVar = 13;
enum myEnum = {Red, Green, Blue};

// How does it work with classes?
class MyClass {
  static myVar = 13; // "Class Fields & Static Properties" which omits "let"
  static enum myEnum = {Red, Green, Blue}; // Now we decided to use "enum"
while we omitted "let" before
  // Maybe "Class Fields & Static Properties" should use "let" and "const"?
}
```

Or:
```javascript
let myVar = 13;
let myEnum = enum {Red, Green, Blue};

// How does it work with classes?
class MyClass {
  static myVar = 13; // "Class Fields & Static Properties" which omits "let"
  static myEnum = enum {Red, Green, Blue}; // All fine?
}
```

---

Do we allow this:
```javascript
let myEnum = enum {Red, Green, Blue};
myEnum.Red; // 0 or Symbol("Red")
myEnum[myEnum.Red]; // Can we get "Red" like this?
```

If we do, how does this work?
```javascript
let myEnum = enum {Red, Green, Blue};
myEnum.Alpha = 3;
myEnum[myEnum.Alpha]; // Who is going to put "Alpha" here? It magically
happens? Probably not.
```

---

Take `HTMLMediaElement` for an example, which has these:
- HTMLMediaElement.HAVE_NOTHING  = 0
- HTMLMediaElement.HAVE_METADATA = 1
- HTMLMediaElement.HAVE_CURRENT_DATA = 2
- HTMLMediaElement.HAVE_FUTURE_DATA = 3
- HTMLMediaElement.HAVE_ENOUGH_DATA = 4

And they can be used like this:
```javascript
if (myVideo.readyState >= HTMLMediaElement.HAVE_METADATA) {
  goodToGo();
} else {
  waitForIt();
}
```

How are we going to achieve the same functionality with "Symbol Enums"?
Don't use Symbols?
Make Symbols comparable or use something special like NumberSymbol which is
comparable like this?
Don't allow users to do this and have them implement methods like
`isReadyStateGreaterThan()` or `readyStateToNumber()`?
???

AFAIK, enums can do this in other languages:
```javascript
let myEnum = enum {Red = 2, Green, Blue};
// Green is 3, Blue is 4.
```

Maybe we can give the user to pick one:
```javascript
let myEnum = enum {Red, Green, Blue}; // Symbol Enum
let myEnum = enum {Red = 0, Green, Blue}; // Number Enum
```

Looks confusing.

---

How will a user be able to achieve an `HTMLMediaElement` like result?
(Making enum'd values properites of the class)
```javascript
class HTMLMediaElement extends HTMLElement {
  // Like this?
  static enum {HAVE_NOTHING, HAVE_METADATA/*, ...*/}

  // A "Number Enum" generates an object so use it with something crazy
like "Class Spread Properties"?
  static ...enum {HAVE_NOTHING, HAVE_METADATA/*, ...*/} // What?

  // Maybe not supporting anything like above, and forcing users to put
enums in a property
  static readyStates = enum {HAVE_NOTHING, HAVE_METADATA/*, ...*/};
}
```
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20151216/3b3e6e2e/attachment-0001.html>


More information about the es-discuss mailing list