Skip to content

pabloalmunia/javacriptdecorators

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JavascriptDecorators.org.

The tools are entirely experimental and evolving. There is no guarantee of they follow the proposed standard correctly.

Table of Content

public private
instance public method private method
static static method static private method
public private
instance public getter
public setter
private getter
private setter
static static getter
static setter
static private getter
static private setter
public private
instance public field
public field with accessor
private field
private field with accessor
static static field
static field with accessor
static private field
static private field with accessor

Class decorators

@decorator
class MyClass {}

decorator parameters

  • value is the class itself

  • context is an object with this content:

{
  kind: "class",
  name: "MyClass",
  getMetadata(key ) { /* ... */ },
  setMetadata(key, value) { /* ... */ },
  addInitializer(initalizer) { /* ... */ }
}

if the decorator is called with @init:

The context object includes the addInitializer() method that receives as a parameter a function that will be executed when the class has been constructed. This function will receive as this the class.

values returned by the decorator

  • undefined, nothing is replaced

  • a new class, it replaces the previous class which was passed as the first parameter

metadata location

MyClass[Symbol.metadata][key].constructor


Method decorators

Public method

class MyClass {
  @decorator
  someMethod() {}
}
decorator parameters
  • value is the method itself

  • context is an object with this content:

{
  kind: "method",
  name: "someMethod",
  isStatic: false,
  isPrivate: false,
  getMetadata(key ) { /* ... */ },
  setMetadata(key, value) { /* ... */ },
  addInitializer(initalizer) { /* ... */ }
}

if the decorator is called with @init:

The context object includes the addInitializer() method that receives as a parameter a function that will be executed when the class is instantiated. This function will receive as this the new object.

values returned by the decorator

  • undefined, nothing is replaced

  • a new function, it replaces the previous method which was passed as the first parameter

metadata location

MyClass.prototype[Symbol.metadata][key].public.someMethod

Static method

class MyClass {
  @decorator
  static someMethod() {}
}
decorator parameters
  • value is the method itself

  • context is an object with this content:

{
  kind: "method",
  name: "someMethod",
  isStatic: true,
  isPrivate: false,
  getMetadata(key ) { /* ... */ },
  setMetadata(key, value) { /* ... */ },
  addInitializer(initalizer) { /* ... */ }
}

if the decorator is called with @init:

The context object includes the addInitializer() method that receives as a parameter a function that will be executed when the class has been constructed. This function will receive as this the class.

values returned by the decorator
  • undefined, nothing is replaced

  • a new function, it replaces the previous method which was passed as the first parameter

metadata location

MyClass[Symbol.metadata][key].public.someMethod

Private method

class MyClass {
  @decorator
  #someMethod() {}
}
decorator parameters
  • value is the method itself

  • context is an object with this content:

{
  kind: "method",
  name: "#someMethod",
  access: {
    get() { /* ... */ },
  },
  isStatic: false,
  isPrivate: true,
  getMetadata(key ) { /* ... */ },
  setMetadata(key, value) { /* ... */ },
  addInitializer(initalizer) { /* ... */ }
}

if the decorator is called with @init:

The context object includes the addInitializer() method that receives as a parameter a function that will be executed when the class is instantiated. This function will receive as this the new object.

values returned by the decorator
  • undefined, nothing is replaced

  • a new function, it replaces the previous method which was passed as the first parameter

metadata location

MyClass.prototype[Symbol.metadata][key].private array.

Static private method

class MyClass {
  @decorator
  static #someMethod() {}
}
decorator parameters
  • value is the method itself

  • context is an object with this content:

{
  kind: "method",
  name: "#someMethod",
  access: {
    get() { /* ... */ },
  },
  isStatic: true,
  isPrivate: true,
  getMetadata(key ) { /* ... */ },
  setMetadata(key, value) { /* ... */ },
  addInitializer(initalizer) { /* ... */ }
}

if the decorator is called with @init:

The context object includes the addInitializer() method that receives as a parameter a function that will be executed when the class has been constructed. This function will receive as this the class.

values returned by the decorator
  • undefined, nothing is replaced

  • a new function, it replaces the previous method which was passed as the first parameter

metadata location

MyClass[Symbol.metadata][key].private array.


Getter and setter decorators

Public getter

class MyClass {
  @decorator
  get someGetter() {}
}
decorator parameters
  • value is the getter itself

  • context is an object with this content:

{
  kind: "getter",
  name: "someGetter",
  isStatic: false,
  isPrivate: false,
  getMetadata(key ) { /* ... */ },
  setMetadata(key, value) { /* ... */ },
  addInitializer(initalizer) { /* ... */ }
}

if the decorator is called with @init:

The context object includes the addInitializer() method that receives as a parameter a function that will be executed when the class is instantiated. This function will receive as this the new object.

values returned by the decorator
  • undefined, nothing is replaced

  • a new function, it replaces the previous getter which was passed as the first parameter

metadata location

MyClass.prototype[Symbol.metadata][key].public.someGetter

Public setter

class MyClass {
  @decorator
  set someSetter(value) {}
}
decorator parameters
  • value is the setter itself

  • context is an object with this content:

{
  kind: "setter",
  name: "someSetter",
  isStatic: false,
  isPrivate: false,
  getMetadata(key ) { /* ... */ },
  setMetadata(key, value) { /* ... */ },
  addInitializer(initalizer) { /* ... */ }
}

if the decorator is called with @init:

The context object includes the addInitializer() method that receives as a parameter a function that will be executed when the class is instantiated. This function will receive as this the new object.

values returned by the decorator
  • undefined, nothing is replaced

  • a new function, it replaces the previous setter which was passed as the first parameter

metadata location

MyClass.prototype[Symbol.metadata][key].public.someSetter

Static getter

class MyClass {
  @decorator
  static get someGetter() {}
}
decorator parameters
  • value is the getter itself

  • context is an object with this content:

{
  kind: "getter",
  name: "someGetter",
  isStatic: true,
  isPrivate: false,
  getMetadata(key ) { /* ... */ },
  setMetadata(key, value) { /* ... */ },
  addInitializer(initalizer) { /* ... */ }
}

if the decorator is called with @init:

The context object includes the addInitializer() method that receives as a parameter a function that will be executed when the class has been constructed. This function will receive as this the class.

values returned by the decorator
  • undefined, nothing is replaced

  • a new function, it replaces the previous getter which was passed as the first parameter

metadata location

MyClass[Symbol.metadata][key].public.someGetter

Static setter

class MyClass {
  @decorator
  static set someSetter(value) {}
}
decorator parameters
  • value is the setter itself

  • context is an object with this content:

{
  kind: "setter",
  name: "someSetter",
  isStatic: true,
  isPrivate: false,
  getMetadata(key ) { /* ... */ },
  setMetadata(key, value) { /* ... */ },
  addInitializer(initalizer) { /* ... */ }
}

if the decorator is called with @init:

The context object includes the addInitializer() method that receives as a parameter a function that will be executed when the class has been constructed. This function will receive as this the class.

values returned by the decorator
  • undefined, nothing is replaced

  • a new function, it replaces the previous setter which was passed as the first parameter

metadata location

MyClass[Symbol.metadata][key].public.someSetter

Private getter

class MyClass {
  @decorator
  get #someGetter() {}
}
decorator parameters
  • value is the getter itself

  • context is an object with this content:

{
  kind: "getter",
  name: "#someGetter",
  access: {
    get() { /* ... */ },
  },
  isStatic: false,
  isPrivate: true,
  getMetadata(key ) { /* ... */ },
  setMetadata(key, value) { /* ... */ },
  addInitializer(initalizer) { /* ... */ }
}

if the decorator is called with @init:

The context object includes the addInitializer() method that receives as a parameter a function that will be executed when the class is instantiated. This function will receive as this the new object.

values returned by the decorator
  • undefined, nothing is replaced

  • a new function, it replaces the previous getter which was passed as the first parameter

metadata location

MyClass.prototype[Symbol.metadata][key].private array.

Private setter

class MyClass {
  @decorator
  set #someSetter(value) {}
}
decorator parameters
  • value is the setter itself

  • context is an object with this content:

{
  kind: "setter",
  name: "#someSetter",
  access: {
    set(value) { /* ... */ },
  },
  isStatic: false,
  isPrivate: true,
  getMetadata(key ) { /* ... */ },
  setMetadata(key, value) { /* ... */ },
  addInitializer(initalizer) { /* ... */ }
}

if the decorator is called with @init:

The context object includes the addInitializer() method that receives as a parameter a function that will be executed when the class is instantiated. This function will receive as this the new object.

values returned by the decorator
  • undefined, nothing is replaced

  • a new function, it replaces the previous setter which was passed as the first parameter

metadata location

MyClass.prototype[Symbol.metadata][key].private array.

Static private getter

class MyClass {
  @decorator
  static get #someGetter() {}
}
decorator parameters
  • value is the getter itself

  • context is an object with this content:

{
  kind: "getter",
  name: "#someGetter",
  access: {
    get() { /* ... */ },
  },
  isStatic: true,
  isPrivate: true,
  getMetadata(key ) { /* ... */ },
  setMetadata(key, value) { /* ... */ },
  addInitializer(initalizer) { /* ... */ }
}

if the decorator is called with @init:

The context object includes the addInitializer() method that receives as a parameter a function that will be executed when the class has been constructed. This function will receive as this the class.

values returned by the decorator
  • undefined, nothing is replaced

  • a new function, it replaces the previous getter which was passed as the first parameter

metadata location

MyClass[Symbol.metadata][key].private array.

Static private setter

class MyClass {
  @decorator
  static set #someSetter(value) {}
}
decorator parameters
  • value is the setter itself

  • context is an object with this content:

{
  kind: "setter",
  name: "#someSetter",
  access: {
    set(value) { /* ... */ },
  },
  isStatic: true,
  isPrivate: true,
  getMetadata(key ) { /* ... */ },
  setMetadata(key, value) { /* ... */ },
  addInitializer(initalizer) { /* ... */ }
}

if the decorator is called with @init:

The context object includes the addInitializer() method that receives as a parameter a function that will be executed when the class has been constructed. This function will receive as this the class.

values returned by the decorator
  • undefined, nothing is replaced

  • a new function, it replaces the previous setter which was passed as the first parameter

metadata location

MyClass[Symbol.metadata][key].private array.


Field decorators

Public field

class MyClass {
  @decorator
  someField = 10;
}
decorator parameters
  • value is undefined

  • context with this object:

{
  kind: "field",
  name: "someField",
  isStatic: false,
  isPrivate: false,
  getMetadata(key ) { /* ... */ },
  setMetadata(key, value) { /* ... */ },
  addInitializer(initalizer) { /* ... */ }
}

if the decorator is called with @init:

The context object includes the addInitializer() method that receives as a parameter a function that will be executed when the class is instantiated. This function will receive as this the new object.

values returned by the decorator
  • undefined, nothing is replaced

  • a new function, its return value will be used as the initial value of the field.

metadata location

MyClass.prototype[Symbol.metadata][key].public.someField

Public field with accessor

class MyClass {
  @decorator 
  accessor someField = 10;
}
decorator parameters
  • value is the accessor field itself (a getter and setter pair)

  • context is an object with this content:

{
  kind: "auto-accesor",
  name: "someField",
  isStatic: false,
  isPrivate: false,
  getMetadata(key ) { /* ... */ },
  setMetadata(key, value) { /* ... */ },
  addInitializer(initalizer) { /* ... */ }
}

if the decorator is called with @init:

The context object includes the addInitializer() method that receives as a parameter a function that will be executed when the class is instantiated. This function will receive as this the new object.

values returned by the decorator
  • undefined, nothing is replaced

  • an object with this structure:

{
  get() {},                      // replaces previous getter which was passed in the first parameter
  set(value) {},                 // replaces previous setter which was passed in the first parameter
  initialize(initialValue) {},   // initializes accessor initial value
}
metadata location

MyClass.prototype[Symbol.metadata][key].public.someField

Static field

class MyClass {
  @decorator
  static someField = 1;
}
decorator parameters
  • value is undefined

  • context is an object with this content:

{
  kind: "field",
  name: "someField",
  isStatic: true,
  isPrivate: false,
  getMetadata(key ) { /* ... */ },
  setMetadata(key, value) { /* ... */ },
  addInitializer(initalizer) { /* ... */ }
}

if the decorator is called with @init:

The context object includes the addInitializer() method that receives as a parameter a function that will be executed when the class has been constructed. This function will receive as this the class.

values returned by the decorator
  • undefined, nothing is replaced

  • a new function, its return value will be used as the initial value of the field.

metadata location

MyClass[Symbol.metadata][key].public.someField

Static field with accessor

class MyClass {
  @decorator
  static accessor someField = 10;
}
decorator parameters
  • value is the accessor field itself (a getter and setter pair)

  • context is an object with this content:

{
  kind: "auto-accesor",
  name: "someField",
  isStatic: true,
  isPrivate: false,
  getMetadata(key ) { /* ... */ },
  setMetadata(key, value) { /* ... */ },
  addInitializer(initalizer) { /* ... */ }
}

if the decorator is called with @init:

The context object includes the addInitializer() method that receives as a parameter a function that will be executed when the class has been constructed. This function will receive as this the class.

values returned by the decorator
  • undefined, nothing is replaced

  • an object with this structure:

{
  get() {},                      // replaces previous getter which was passed in the first parameter
  set(value) {},                 // replaces previous setter which was passed in the first parameter
  initialize(initialValue) {},   // initializes accessor initial value
}
metadata location

MyClass[Symbol.metadata][key].public.someField

Private field

class MyClass {
  @decorator
  #someField = 1;
}
decorator parameters
  • value is undefined

  • context is an object with this content:

{
  kind: "field",
  name: "#someField",
  isStatic: true,
  isPrivate: false,
  getMetadata(key ) { /* ... */ },
  setMetadata(key, value) { /* ... */ },
  addInitializer(initalizer) { /* ... */ }
}

if the decorator is called with @init:

The context object includes the addInitializer() method that receives as a parameter a function that will be executed when the class is instantiated. This function will receive as this the new object.

values returned by the decorator
  • undefined, nothing is replaced

  • a new function, its return value will be used as the initial value of the field.

metadata location

MyClass.prototype[Symbol.metadata][key].private array.

Private field with accessor

class MyClass {
  @decorator 
  accessor #someField = 10;
}
decorator parameters
  • value is the accessor field itself (a getter and setter pair)

  • context is an object with this content:

{
  kind: "auto-accesor",
  name: "someField",
  accessor: {
    get() { /* ... */ },
    set() { /* ... */ }
  },
  isStatic: false,
  isPrivate: true,
  getMetadata(key ) { /* ... */ },
  setMetadata(key, value) { /* ... */ },
  addInitializer(initalizer) { /* ... */ }
}

if the decorator is called with @init:

The context object includes the addInitializer() method that receives as a parameter a function that will be executed when the class is instantiated. This function will receive as this the new object.

values returned by the decorator
  • undefined, nothing is replaced

  • an object with this structure:

{
  get() {},                      // replaces previous getter which was passed in the first parameter
  set(value) {},                 // replaces previous setter which was passed in the first parameter
  initialize(initialValue) {},   // initializes accessor initial value
}
metadata location

MyClass.prototype[Symbol.metadata][key].public.someField

Static private field

class MyClass {
  @decorator
  static #someField = 0;
}
decorator parameters
  • value is the field itself

  • context is an object with this content:

{
  kind: "setter",
  name: "#someField",
  access: {
    get() { /* ... */ },
    set(value) { /* ... */ },
  },
  isStatic: true,
  isPrivate: true,
  getMetadata(key ) { /* ... */ },
  setMetadata(key, value) { /* ... */ },
  addInitializer(initalizer) { /* ... */ }
}

if the decorator is called with @init:

The context object includes the addInitializer() method that receives as a parameter a function that will be executed when the class has been constructed. This function will receive as this the class.

values returned by the decorator
  • undefined, nothing is replaced

  • a new function, its return value will be used as the initial value of the field.

metadata location

MyClass[Symbol.metadata][key].private array.

Static private field with accessor

class MyClass {
  @decorator
  static accessor #someField = 10;
}
decorator parameters
  • value is the accessor field itself (a getter and setter pair)

  • context is an object with this content:

{
  kind: "auto-accesor",
  name: "someField",
  access: {
    get() { /* ... */ },
    set(v) { /* ... */ }
  },
  isStatic: true,
  isPrivate: true,
  getMetadata(key ) { /* ... */ },
  setMetadata(key, value) { /* ... */ },
  addInitializer(initalizer) { /* ... */ }
}

if the decorator is called with @init:

The context object includes the addInitializer() method that receives as a parameter a function that will be executed when the class has been constructed. This function will receive as this the class.

values returned by the decorator
  • undefined, nothing is replaced

  • an object with this structure:

{
  get() {},                      // replaces previous getter which was passed in the first parameter
  set(value) {},                 // replaces previous setter which was passed in the first parameter
  initialize(initialValue) {},   // initializes accessor initial value
}
metadata location

MyClass[Symbol.metadata][key].public.someField



Functionality not supported yet

  • Export export or export default.
  • Anonymous class.

About

JavascriptDecorators.org

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published