In my application,I have to build a standalone lib for other people use,so I create new object like this:
function MyService(){ //xxxxxxx... } MyService.prototype.login=function(name,pass){ //here } MyService.prototype.LoadDataFromServer(){ //use the ajax get data from server,when get the data,I will eval them : var data=parseData(request.responseText); //now,the parseData is a private method which should not be exposed to the user,but it need the reference of the MyService object(this),so I have to use the following code: var this_ref=this; function parseData(res){ this_ref.xxxx=..... } } MyService.prototype.parseData=function(res){ this.xxxxx=.... } This will make the paresData function to the user.
Now,I wonder which is better?