proposal-attributes
A proposal for ECMA-262 that suggests the addition of Attributes feature.
Syntax
code:js
class Foo {}
function foo() {}
class Foo {
method() {
}
}
Attributes are EcmaScript classes which are attributed by Attribute attribute
code:javascript
class MyAttribute {}
The instance of an attribute is set to the attributed element, and can be retrieved by the well known symbol Symbol.attributes.
A class attribute
code:javascript
class Foo {}
A function attribute
code:js
function foo() {}
Transpile
Attributes are roughly transpiled as below
code:js
class MyAttribute {
}
class Foo {}
This transpiles into
code:js
Symbol.attributes ??= Symbol('Symbol.attributes')
if (typeof globalThis.Attribute === 'undefined') {
globalThis.Attribute = class Attribute {}
}
class MyAttribute {}
class Foo {}
throw new TypeError('MyAttribute can\'t be used as Attribute because it is not an Attribute')
}
Prior Art
Attributes
Decorators
Annotations
Note
Anyone can fork, copy, or steal this document and/or idea.
Reference