Estoy creando un intérprete que lee
variable1: 2 variable2: 400 variable3: 31desde un archivo de texto e inicializa las variables en tiempo de ejecución. usando eval() y expresiones regulares
class Rules{ getSegmentArgs_string(sgmnt, scope) { let argarray = new Array; let vardeclaration; for(let i=0; i<this.rules[sgmnt].length; i++) { let regexp = /(\w+): ([0-9\.]+)/g; for (const match of this.rules[sgmnt][i].matchAll(regexp)) { vardeclaration = (scope+match[1].toString() + " = "+match[2].toString()+";"); argarray[i] = vardeclaration; } } return argarray; } setSegment(sgmnt) { this.segment = sgmnt; } init() { this.defaultvars = this.getSegmentArgs_string(this.segment,"this.") for(let i=0; i<this.defaultvars.length; i++) { eval(this.defaultvars[i]); } delete(this.rules); delete(this.defaultvars); delete(this.segment); } constructor() { this.rules = this.dump(); } } let rules = new Rules; rules.setSegment(3); rules.init();Sin embargo, no puedo entender cómo acceder a estas variables inicializadas en un bucle for que arroja el nombre de cada variable, así como su valor.
for (const variables in rules) { console.log({variales}); console.log({variables}.value); }Soy capaz de acceder al valor al hacer
console.log(rules.variables1,rules.variables2,rules.variables3)pero debido a la naturaleza de la tarea, necesito recorrer todas las variables sin nombrarlas en el código.