Creating a javascript class with an object containing functions -
I'm trying to create a JavaScript "class" and it's working a bit better, but the engine. tile.draw isn 't working as an engine. I can not seem to do this for working inside the system. Is it not possible to create an object and add a function inside it, like I did? How do you guys Any help is appreciated :)
var engineclass = (function () {var engine = function} {this.canvas = document.getElementById ('game'); this.handle = This.canvas.getContext ('2D');}; engine.protitip.start = function (mapdata) {this.tile.draw (mapData);} engine.protitip.til = {draw: function (x, y , Tile) {this.handle .Filtext (tile, x * 16, y * 16);}}} return engine;}) (); Var engine = new engine class ();
The above comment should not try to apply sections on javascript that are prototypical The language is correct.
Technically, the reason for this does not work that whenever you start a function using dot notation (like some.method () ), the function In this case, when you call this.tile.draw (mapData) , tile.draw is binded to the left of the dot from this > Function is applied with yes tile objects, instead of engine objects as you expect this To overcome Area, but the best advice is to have your attitude instead of JavaScript prototypes to try to strengthen its class-based mentality.
Comments
Post a Comment