I want to create a class in Java from a class name and a variable number of arguments (that is, arguments to Object [] with a variable length). Is there any way to achieve this?
Basically, the method will look like this in Javascript
function createClass(classname, args) { protoObject = Object.create(window[classname].prototype); return window[classname].apply(protoObject,args) || protoObject; }
A simpler function just for calling the function will look like
function callFunction(functionName, args) { return window[functionName].apply(null,args); }
Thanks!
For clarification, this will be an example of use in Javascript:
function multiplyResult(var1,var2) { return var1*var2; } var result = callFunction("multiplyResult", ["5", "2"]); // == 10 function multiplyObject(var1,var2) { var result = var1 * var2; this.getResult = function() { return result }; } var result = createClass("multiplyObject", ["5", "2"]).getResult(); // == 10
source share