Rookie question. It could be a possible duplicate, but I can't wrap my head around how to restructure the code. How should I structure the below code so that the console would print the following:
Here1 Here2 Here1 Here2 Here1 Here2
Now it goes:
Here1 Here1 Here1 Here2 Here2 Here2
Thanks for your help.
var record;
for ( i = 0; i < 3; i++ ) {
sendRequest(selectTestsToRun('something1'), 'someTest1');
}
this.someTest1 = function(resObj, testToRun){
console.log('Here1');
record = resObj.value;
sendRequest(selectTestsToRun('something2'), 'someTest2');
};
this.someTest2 = function(resObj, testToRun){
console.log('Here2');
};
function selectTestsToRun(toDo){
var data;
switch( toDo) {
case 'something1':
data = 'postMessage';
break;
case 'something2':
data = 'postMessage'+record;
break;
}
return data;
}
function sendRequest(data , toDo ){
GM_xmlhttpRequest({
method: 'POST',
url: url,
data: data,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
onload: function(response) {
var resObj = JSON.parse(response);
this[toDo](resObj,toDo);
}
});
}