javascript - Having another class as a static property on a class -


read example below*, don't pay attention eventemitter inheritance, please – shows utility of class syntax.

i realize example not correct es2015, since there no such thing static class statement.

what syntactically lean way make work in es2015?

class app extends eventemitter {   addpage(name) {     this[name] = new app.page;     this.emit("page-added");   }    static class page extends eventemitter {     constructor() {       super();       this._paragraphs = [];     }      addparagraph(text) {       this._paragraphs.push(text);       this.emit("paragraph-added");     }   } } 

should split , use class expression, below? seems less elegant.

class app extends eventemitter {   addpage(name) {     this[name] = new app.page;     this.emit("page-added");   } }  app.page = class extends eventemitter {   constructor() {     super();     this._paragraphs = [];   }    addparagraph(text) {     this._paragraphs.push(text);     this.emit("paragraph-added");   } }; 

should split , use class expression?

yes, that's way go. if insist on using declaration, you'd have make app.page = page assignment afterwards.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -