class Parameters { constructor() { this.c2c = false; this.c1 = ''; this.c2 = ''; this.c3 = ''; this.numbers = []; this.num = ''; } get c1() { return this.s1 } get c2() { return this.s2 } get c3() { return this.s3 } get number() { return this.num } set c1(text) { this.s1 = text; this.updateFields() } set c2(text) { this.s2 = text; this.updateFields(); } set c3(text) { this.s3 = text; this.updateFields(); } set number(number) { this.num = this.numbers.includes(number) ? number : ''; this.updateFields(); } findFields() { return $('*[data-original]'); } updateFields() { (!this.c2c) ? this.updateSubids() : this.updateNumbers(); } updateSubids() { let self = this; let fields = this.findFields(); if( fields.length > 0 ) { fields.each(function(field) { let replacement = $(this).attr('data-original') .replace("xxc1xx", self.c1) .replace("xxc2xx", self.c2) .replace("xxc3xx", self.c3); $(this).text(replacement); }); } } updateNumbers() { let self = this; let fields = this.findFields(); if( fields.length > 0 ) { fields.each(function(field) { let replacement = $(this).attr('data-original') .replace(/xxc2cxx/g, self.number); $(this).text(replacement); }); } } }