I wanted to clearInterval() and I can do so using clearInterval(myInterval) but why can I not using clearInterval(this) ?
Here is the code that works :
var test = setInterval(function(){
request.post({url: myURL, form: {
user : myUser,
pass : myPass
function(err,res,body){
if(res.statusCode === 302) clearInterval(test);
})
}, 1100)
Here is the code that doesn't work :
setInterval(function(){
var that = this;
request.post({url: myURL, form: {
user : myUser,
pass : myPass
function(err,res,body){
if(res.statusCode === 302) clearInterval(that);
})
}, 1100)
Edit 1 : I am sorry for the poor question. I am not much familiar with the concept of 'this' and intuitively thought using 'this' I can clearInterval(). The reason for that is because when I console.log(test) in the first code and in console.log(this) in the second code inside the setInterval function, the output was the same, hence the intuition. Well, I should rather study about 'this'. Thank you every one for your answers and comments. Much appreciated.