Last active
May 5, 2016 22:04
-
-
Save TyIsI/d5a59b555178d6c0ef3f7ee2ba701a8e to your computer and use it in GitHub Desktop.
Javascript dynamic class loading and dynamic method loading
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example class | |
function ExampleClass() { | |
// Example Method | |
this.ExampleMethod = function ( args ) { | |
// Log to console | |
return console.log( "Name: " + args.message ); | |
} | |
} | |
// Variables | |
var className = 'ExampleClass'; | |
var methodName = 'ExampleMethod'; | |
var args = { "message" : "Success!" }; | |
// Set up objectsArray (cache) | |
var objectsArray = {}; | |
// Dynamically create new instance | |
objectsArray[className] = new window[className](); | |
// Dynamically call the method | |
objectsArray[className][methodName]( args ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment