I'm new to the prototype structure, and I'm having trouble figuring this one out. Here's my JavaScript code.
var Game = function ()
{
//some variables
};
Game.prototype.block =
{
spawn: function () {
var t1 = new this.inst;
},
inst : {
x: 5,
y: 0,
type: ''
}
};
When I try to create a new object "inst" I get the following error: TypeError: object is not a function. What am I doing incorrectly?
instobject? The onlyinstI see is already an object onGame.prototype.block. Thenew this.instwill never work becauseinstis not a function.instobject, you can do that usingObject.create, so you could dovar t1 = Object.create(this.inst);, assuming you're doing something likevar game = new Game(); game.block.spawn();