I found this question, which helped me a lot and I was able to successfully utilize 2 integers with a settimeout(). However, when passing objects it doesn't seem to work.
Code:
$(document).ready(function() {
var me = {
x: 0,
y: 0
}
var child = {
x: 0,
y: 0
}
function showxydiff(obj1, obj2, when) {
var xdiff = (obj1.x - obj2.x);
var ydiff = (obj1.y - obj2.y);
$('#' + when).append(xdiff + ':' + ydiff + '... ');
};
for (var i = 1; i <= 5; i++) {
child.x = Math.floor((Math.random()*100)+1);
child.y = Math.floor((Math.random()*100)+1);
showxydiff(child, me, 'now');
setTimeout(function (obj1, obj2) {
return function () {
showxydiff(obj1, obj2, 'later');
}
}(child,me), 500);
}
});
And here are the results:
now: 57:37... 98:50... 72:87... 66:31... 28:30...
later: 28:30... 28:30... 28:30... 28:30... 28:30...