i`m trying to creat a little game using javascript and everything went well until i have to fire something, i nedeed to instantiate a "bullet" and fire it, but when calling "new bullet()" i got an "Uncaught TypeError: undefined is not a function ". How do i instantiate an object inside another object method?
this is what i done
function bullet(){
//here it would be state for the bullet, like x and y and thigs
console.log("bullet created");
}
function gun(){
//state for the gun, amount of bullets and sort
console.log("gun created");
this.fire = function(){
//here we instantiate a bullet and fire it
console.log("begin fire");
var bullet = new bullet();
console.log("created bullet to fire");
}
}
var gun = new gun();
gun.fire();
var gunandvar bulletto something else...