function ExecuteRect(code) { function rectangle(wid,hei,col) { let obj = { width:0, height:0, color:0, calcArea:function(){return Number(this.height)*Number(this.width); } }; obj.width = wid; obj.height = hei; obj.color = col; return obj; } let executable = eval(code); new Function(executable)(); } let code = `let rect = rectangle(4, 5, 'red'); console.log(rect.width); console.log(rect.height); console.log(rect.color); console.log(rect.calcArea());`; ExecuteRect(code);