You can't include a for-loop like that because it is a statement and does not evaluate to an expression. You can only have expressions as arguments to a function, and the {...}
terms here are object literals, which are just expressions that evaluate to an object.
What you need to do is create an array with your for-loop and pass that in to your function using Function.apply
.
Here is an example:
var args = [];
for (var i = 0; i < test.length; i++) {
args.push({
theName : test[i],
theDefault : true
});
}
USP.init.apply(USP, args)
The apply
method takes two arguments. The first one is the value of this
inside the function; it has to be the object you want to call the function on. The second argument is an array, it will be passed into the function as its arguments
.