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?
If you want to create objects that inherit from the
instobject, you can do that usingObject.create, withvar t1 = Object.create(this.inst);.So then your code would look something like this;
And the
.spawn()method would have a variable that references an object that inherits from theGame.prototype.block.instobject.