Create object from string in JavaScript ECMAScript 6 - Javascript Object

Javascript examples for Object:Constructor

Description

Create object from string in JavaScript ECMAScript 6

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/*from  w w  w  .j  ava  2s  .  c om*/
"use strict";
class Person {
    constructor(x, y) {
        this.x = x;
        this.y = y;
    }
}
window.classes = {};
window.classes.Person = Person;
document.body.innerText = JSON.stringify(new window.classes["Person"](1, 2));
    }

      </script> 
   </head> 
   <body>    
   </body>
</html>

Related Tutorials