for example, say I use a factory to create a group of objects:
function factory() {
e.x = 0;
e.y = 0;
return e;
}
How do I pass these objects into a render function?
For example:
function render() {
a[0].someMethod;
}
function init() {
for(i=0;i<10;i++) {
things[i] = factory();
}
setInterval(render(things),40);
}
You need to use closure there:
setIntervalaccepts callback function (function with name without()) but when you do:You are actually calling the function (because of
(things)parenthesis) right there insidesetIntervalwhich is wrong.