shorthand attributes for properties of the global object

Example:

let title = "HELLO" {type: /[A-Z]/ || String || typeVerificationFunction, writable: true, success: callbackInSuccessCase, failure: callbackInFailureCase}

title = 123 //dispatch the callbackInFailureCase OR throw a SyntaxError

Beyond the current attributes the shorthand can add new attributes for type checking with regular expressions, function, or data type as String, Number, Date etc., and can add callbacks to success or failure cases.

Hi Mateus!
Can you please elaborate on the rationale of this feature? What would be the use cases, where would this be useful? What kind of programming does this enable that was not possible before? Is it possible to desugar/transpile the new syntax? And why should this be limited to properties of the global object only?

1 Like

Hi, @bergus!

This shorthand syntax is an idea inspired by Object.defineProperty and by others programming languages as C++.

My suggestion is to global properties (as variables and constants), and can be improved to be for user-defined objects also, and can be improved to use a more friendly writing way.

The goals of this suggestion are three:

  1. Be an alternative, in vanilla ECMAScript, to enforce type-checking
  2. Be a shorthand alternative to Object.defineProperty()
  3. Create an way to authors write more descriptive text units to be interpreted by the host environment and by the others authors