/ Published 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.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<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>
URL: http://www.apphp.com/index.php?snippet=javascript-create-object-from-variable
Comments
