$.post (ajaxUrl, {action:'get_seconds_to_next_cron'}, function (data) {
countdown = data + 600; //is this in global scope now?
setInterval('updateClock();',1000 );
},'json');
function updateClock() {
countdown--;
console.log(countdown); //output for verification
}
Hi [first ever stackoverflow question] the above is a solution for a timer on a shopping cart linked to our server time and a cron job.
I am worried that countdown becomes part of the global namespace and thus not best practise etc.
below is a bit of test code that tries to go about setting up things differently to (perhaps) do a cleaner job as far as scope is concerned.
var myWrapper = {
count: 600,
passCount : 'myWrapper.myCount(' +this.count+ ')',
myCount: function() {
this.count--;
console.log(this.count); //output for verification
},
setCounter: function() {
setInterval(this.passCount, 1000);
}
};
myWrapper.setCounter();
My comprehension of scope is intermediate at best so any feedback will be interesting and potentially helpful for my understanding.
thanks.