Create instance of “Class” Using “Reflection” in JavaScript

后端 未结 3 652
醉话见心
醉话见心 2021-01-19 05:28

I searched the web for some way to create instance of \"Class\" in \"reflection\" using javaScript but I found nothing.

generally i\'m trying to do someting like jav

3条回答
  •  孤街浪徒
    2021-01-19 06:12

    Classes in Javascript are nothing but global functions. So you should be able to do this:

    var o = new window["MyClassName"];
    

    for example:

    var o = new window["Array"];
    

    Keep in mind that this example is just an example. Arrays should be created via [] syntax.

提交回复
热议问题