I have a constructor property that expects an array of type (just for example) Dog. Rather than creating an array, filling it with Dogs and then passing that to the property I would like to create that array dynamically in a for-loop.
So instead of
(...) new ConstructorFoo({
property: [
new Dog("1"),
new Dog("2")
]
});
I would like to use something like this:
(...) new ConstructorFoo({
property: function() {
var d = [];
for(var i = 0; i < 10; i++) {
d.push(new Dog(i));
}
return d;
}
});
But as far as I understand this throws an exception because of type mismatch. property expects an array of dogs but gets a function (correct?).
I hope my question makes sense.
propertydoesn't expect anything, it's an attribute in an object, being passed toConstructorFoo.ConstructorFooexpects its argument to be of a certain form, and we can't tell you exactly what unless you showConstructorFoo. If you just want to create an array before passing it toConstructorFoo, then georg's answer should serve you well. If something is being used todefineProperty, then you will need to show us what you are doing.