var Singleton = {
Sdata : "some data",
modify-data : function(data, callback){
Sdata = data;
callback(Sdata);
}
}
Here, does Sdata get overwritten by two different requests accessing the function modify-data at the same time?
Can it be averted like following:
var Singleton = {
modify-data : function(data, callback){
var Sdata = data;
callback(Sdata);
}
}
here, does a new var Sdata get created every time? And if two requests access modify-data at the same time, does it create a new instance of Sdata for each?
Methods are also first-class objects in javascript. So, if modify-data is called, its scope should be encapsulated. So, to answer your questions, yes and yes.