Revision: 66787
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at July 2, 2014 18:06 by apphp-snippets
Initial Code
<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>
Initial URL
http://www.apphp.com/index.php?snippet=javascript-create-object-from-variable
Initial Description
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.
Initial Title
Create new Object From Variable in JavaScript
Initial Tags
javascript, object
Initial Language
JavaScript