I am building an algorithm in typescript/ionic 2 that requires a function hierarchy (functions within functions). I am 99% sure that there is no way to avoid having nested functions because of the google API (long explanation required, just trust me on that)
I will use a simple demo that illustrates my problem to avoid posting 300 lines of code.
The problem involves accessing and manipulating global variables within the nested functions. I need a way of setting the this.secondvar in the secondSet function. Are there any ways to achieve this?
export class HomePage {
public firstVar = [];
public secondvar;
constructor(public navCtrl: NavController) {
}
ionViewDidLoad(){
this.setVar();
}
setVar(){
this.firstVar.push("hello", "goodbye");
console.log();
getVar();
function getVar(){
//console.log(this.lol); unable to access
secondSet();
function secondSet(){
console.log("test")
//this.secondVar = "hello" //how do i set this ?
}
}
}
}