function cloneObject(obj) {
var clone = {};
for(var i in obj) {
if(typeof(obj[i])=="object" && obj[i] != null)
clone[i] = cloneObject(obj[i]);
else
clone[i] = obj[i];
}
return clone;
}
modules.Projectiles = (function() {
return {
projectiles: [],
new: function(cv, x, y, width, height, direction, speed) {
this.projectiles.push(
new Projectile(cv, x, y, width, height, direction, speed));
},
getActive: function() {
return this.projectiles.length;
},
draw: function() {
for (var i = 0; i < this.projectiles.length; i++) {
this.projectiles[i].draw();
}
}
};
var batman = (function () {
var identity = "Bruce Wayne";
return {
fightCrime: function () {
console.log("Cleaning up Gotham.");
},
goCivilian: function () {
console.log("Attend social events as " + identity);
}
};
})();
new
method just push a new projectile object inside that array
this
is the object we’re returning
modules.Projectiles = (function() {
var projectiles = [];
return {
new: function(cv, x, y, width, height, direction, speed) {
projectiles.push(
new Projectile(cv, x, y, width, height, direction, speed));
},
getActive: function() {
return projectiles.length;
},
draw: function() {
for (var i = 0; i < projectiles.length; i++) {
projectiles[i].draw();
}
}
};
})();