javascript game level inheritance -


i'm rewriting game i've designed in flash/as3.0 javascript , having trouble wrapping head around prototypes, having learned classes. i've read ton of info , still not quite sure how apply scenario.

so... in as3.0 project had level class, had guts of happens in levels of game, enter_frame functionality etc. extended class each level, level specific details such item placement, terrain details etc... question how efficient , 'proper' way this.

right have 2 functions:

function level() { //generic level functionality }  function level1() { //level1 specific functionality } 

then i've read should have set

level1.prototype = new level(); 

but have found executes within level function @ runtime, don't want. ideally i'd start button instantiate level1, , level1 have properties , methods of level - and, if possible, execute within level1's , level's constructor when happens... possible?

i'm sure it's obvious can't seem click, sorry if i'm asking silly question. appreciation in advance.

to avoid executing constructor when establishing inheritance, can use object.create():

level1.prototype = object.create(level.prototype); 

though, "chain" constructor calls, you'll need call level within level1:

function level1() {     level.call(this);      // ... } 

using call allows pass context (this) along both constructors work same object.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -