class Serializer {
constructor(structItem) {
this.struct = structItem
}
toFormatA(){
return `format A: ((${this.struct.data}))`
}
toFormatB(){
return `format B: <<${this.struct.data}>>`
}
}
class Struct {
constructor(data) {
this.data = data
this.serialize = new Serializer(this)
}
}
let s = new Struct("example data")
s.serialize.toFormatA()
s.serialize.toFormatB()
"format A: ((example data))"
"format B: <<example data>>"