Create new Object From Variable in JavaScript
This example of code allows you to create a new object in javascript (using simple inheritance)
such that the class of the object is defined from a variable. After creating the object you may use
it for your purposes.
[View All Snippets]
[View All Snippets]
Show Plain Text »
- <script type="text/javascript">
- var className = "PluginClass";
- // get a reference to the class object itself
- // (we've assumed the class is defined in a global scope)
- var myclass = window[className];
- // now you have a reference to the object, the new keyword will work:
- var inst = new myclass();
- // now call to the required method of your class
- // alert(inst.validate("4111111111111111", "visa"));
- </script>