1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
'use strict'; class Message{ constructor (type, data) { this.t = type; this.d = data; } stringify () { var dat = this.d if(typeof dat !== "string"){ dat = JSON.stringify(dat); } return JSON.stringify({type: this.t, data: dat}); } }