KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Is this possible? I am creating a single base factory function to drive factories of different types (but have some similarities) and I want to be able to pass arguments as an array to the base factory which then possibly creates an instance of a new object populating the arguments of the constructor of the relevant class via an array. In JavaScript it's possible to use an array to call a function with multiple arguments by using the apply method: namespace.myFunc = function(arg1, arg2) { //do something; } var result = namespace.myFunc("arg1","arg2"); //this is the same as above: var r = [ "arg1","arg2" ]; var result = myFunc.apply(namespace, r); It doesn't seem as if there's anyway to create an instance of an object using apply though, is there? Something like (this doesn't work): var instance = new MyClass.apply(namespace, r);
Tags (comma-separated)
Save Edits
Cancel