Answer the question
In order to leave comments, you need to log in
How to create a constructor method?
Hello! I am writing a small game based on MVC. Got a question. How to create an object of some element of the world inside the Model property. And how to call it correctly so that the resulting object is a Model object. I do that, but the object is not added.
var model = {
CreateGameObject: function(elem) {
var gameArea = this.area;
this.elName = elem;
this.makeDiv = function() {
var parentElem = document.getElementById("game-area");
console.log(parentElem);
var div = document.createElement("div");
div.setAttribute("id", elem);
div.className = "wall";
parentElem.appendChild(div)
}
},
mainMethod: function(){
var obj1 = new this.CreateGameObject("obj1");
}
};
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question