Advertisement
Stan0033

Untitled

Feb 10th, 2022
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. function ExecuteRect(code)
  2. {
  3. function rectangle(wid,hei,col)
  4.  
  5. {
  6.  
  7. let obj = {
  8. width:0,
  9. height:0,
  10. color:0,
  11. calcArea:function(){return Number(this.height)*Number(this.width); }
  12.  
  13. };
  14. obj.width = wid;
  15. obj.height = hei;
  16. obj.color = col;
  17.  
  18. return obj;
  19. }
  20.  
  21. let executable = eval(code);
  22. new Function(executable)();
  23.  
  24. }
  25.  
  26.  
  27.  
  28. let code =
  29. `let rect = rectangle(4, 5, 'red');
  30. console.log(rect.width);
  31. console.log(rect.height);
  32. console.log(rect.color);
  33. console.log(rect.calcArea());`;
  34. ExecuteRect(code);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement