class - Javascript Inheritance and the words "this" and "that" -


this question has answer here:

i have class use methods event listeners, don't use this that in methods.

this base class:

function modal(){      var = this;      this.opened = false;      this.open = function(){           that.opened = true;          var id = this.id;          // more code      };      this.close = function () {           if (that.opened) // something;      }; } 

this inherited class:

function modalbook(){      var = this;      this.open = function(){           that.opened = true;          var id = this.id;          // more code      }; } modalbook.prototype = new modal();  var modalbook = new modalbook(); 

now value of modal.opened true when modal opened when it's closed value false.

on debugging on line of this.close, saw that instance of modal, , modalbook instance of modalbook.

so question is: how preserve value of this in both methods modalbook?

what's happening there modalbook.prototype=new modal() modalbook 'inheriting' modal. variables belong each constructor in scopes , properties overwritten. so:

  • that in modal stay locally in modal
  • that in modalbook instante of modalbook
  • but open() method exist modalbook.open() (you're overwritting other one) that instance of modalbook , other that doesn't exist in scope.

i think have design problem. maybe use properties different name thats.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -