javascript - Get "this" within the parent class -


my problem can't access proper this object in parent class.

parent class :

viewcontroller.prototype.display = function() {     console.log(this); // log window object }; 

child class :

parentmissionsviewcontroller.prototype = object.create(viewcontroller.prototype); parentmissionsviewcontroller.prototype.constructor = parentmissionsviewcontroller; parentmissionsviewcontroller.prototype.parent = viewcontroller.prototype;  parentmissionsviewcontroller.prototype.display = function() {     // other stuff here     this.parent.display.call(); }; 

i don't why isn't current object, if can explain me ?

if call

this.parent.display(); 

then looks like:

var = this.parent; that.display(); 

which you, suppose, wanted avert. using call way, need provide value this:

this.parent.display.call(this /* , arg, arg... */); 

see the signature of call @ mdn.


Comments

Popular posts from this blog

javascript - How to name a jQuery function to make a browser's back button work? -

python - Django-easy-pdf: xhtml2pdf reporting reportlab 2.2+ is required, but 3.0 installed -

collision detection - C++ library for mesh to mesh intersection: what is available? -