The Modern JavaScript Collection by Aurelio De Rosa

The Modern JavaScript Collection by Aurelio De Rosa

Author:Aurelio De Rosa [Various]
Language: eng
Format: epub
Publisher: SitePoint
Published: 2017-08-08T23:00:00+00:00


ESnext Class Fields

The class fields proposal allows properties to be initialized at the top of a class:

class MyClass { a = 1; b = 2; c = 3; }

This is equivalent to:

class MyClass { constructor() { this.a = 1; this.b = 2; this.c = 3; } }

Initializers are executed before any constructor runs (presuming a constructor is still necessary).

Static Class Fields

Class fields permit static properties to be declared within the class. For example:

class MyClass { x = 1; y = 2; static z = 3; } console.log( MyClass.z ); // 3

The inelegant ES6 equivalent:

class MyClass { constructor() { this.x = 1; this.y = 2; } } MyClass.z = 3; console.log( MyClass.z ); // 3



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.