I coded a class in JavaScript, and I'm trying to modify one of my public properties inside a private function.
Here is an example of my code:
MyClass = function(callback){
this.tabs = [];
var tabs_callback = function(){};
this.setTabsCallback = function(callback) {
tabs_callback = callback;
}
var _doStuff = function(callback) {
// doing stuff
this.tabs = [1, 2, 3];
console.log("Inside doStuff");
console.log(this.tabs);
tabs_callback();
}
this.doStuff = function() {
_doStuff();
}
}
var myObject = new MyClass();
myObject.setTabsCallback(function () {
console.log("Inside callback");
console.log(myObject.tabs);
});
myObject.doStuff();
And here is what I get in the console:
Inside doStuff
[ 1, 2, 3 ]
Inside callback
[]
Why am I not able to see my modification from the callback function?