Possible Duplicate:
What underlies this JavaScript idiom: var self = this?
I am confused that when to use self and this in javascript.
I know that this refers to current context and self refers to current window.
As I am developing an application in Titanium. I want to know when to use self or this
OR does is there is any concept of self in titanium development.
here is the sample code that i am doing in my titanium commonJS module
var auth = require('/SDKTest/auth');
var nodeAPI = require('/SDKTest/nodeAPI');
function myAPI() {
this.auth = auth;
this.nodeAPI = nodeAPI;
return this;
}
module.exports = myAPI;
This code works, but can I use self in place of this ? And instead of using this i can create a namespace and do something like this:
function myAPI() {
var api = {};
api.auth = auth;
api.nodeAPI = nodeAPI;
return api;
}
both the approaches work but what is the use of using this over here