Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing outer scope from inner scope

I have a type that looks a little something like this:

var x = function(){
    this.y = function(){

    }

    this.z = function(){
        ...
        this.A = function(){
            CALLING POINT
        }
    }
}

From calling point, I'm attempting to call function this.y. I don't need to pass any parameters, but when I set some stuff from this.A, I need to call this.y.

Is this possible? I'm OK with passing extra parameters to functions to make it possible.

like image 504
Nathan Avatar asked Mar 08 '16 21:03

Nathan


1 Answers

Is this possible?

Yes, you can assign this reference to another variable and then call function y on it

this.z = function() {
    var self = this;
    this.A = function() {
        self.y();
    }
}
like image 138
isvforall Avatar answered Oct 26 '22 17:10

isvforall