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

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

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