I have code like:
MyClass = {
init: function(){
marker = 0;
//I call foo() and bar() from here
},
foo: function(){
//I want to access & update marker here
},
bar: function(){
//This function also accesses updates marker
}
};
I can access the marker by passing it as a parameter to functions but I will not be able to update it.
So, how do I manage creating a variable marker such that all three functions can share it? I don’t want to write any code outside MyClass.
Put
markerin MyClass, not in init, where it is right now.