1

I make a simple class in JS

var Display = function(element) {
    this.element = element
};

Display.prototype.init = function() {
    this.element.addEventListener('click', this.hide);
};

Display.prototype.hide = function() {
    alert(42);
}

Then I make another class extend Display

var Menu = function(element) {
    Display.call(this);
}

Menu.prototype = new Display();
Menu.prototype.constructor = Menu;

Menu.prototype.hide = function() {
    console.log(this); //the element attached with click event
    Display.show.call(this);
}

The question is, in my function Show, 'this' is the element attached with click. But for 'call', i need to pass the scope of my object 'menu', right? But 'call' just work if i pass 'this', and not work if i pass the 'menu' object.

Or I don't understand 'this' scope, or i don't understand the 'call' methods...

Anybody can explain this for me?

Mr-Cutia
  • 83
  • 1
  • 5

0 Answers0