fixes double call of function as parameter (#158)

fixed by changing the evaluate parameters function to modify the trial
object directly, so the function is replaced by its value.
This commit is contained in:
Josh de Leeuw 2015-12-08 10:35:29 -05:00
parent ed4b2ba99c
commit dba6c4befc
2 changed files with 7 additions and 13 deletions

View File

@ -145,11 +145,8 @@
// handle callback at whole-experiment level
opts.on_trial_finish();
// if timing_post_trial is a function, evaluate it
var time_gap = (typeof current_trial.timing_post_trial == 'function') ? current_trial.timing_post_trial() : current_trial.timing_post_trial;
if(time_gap > 0){
setTimeout(next_trial, time_gap);
if(current_trial.timing_post_trial > 0){
setTimeout(next_trial, current_trial.timing_post_trial);
} else {
next_trial();
}
@ -616,7 +613,7 @@
var progress = jsPsych.progress();
var trial = jsPsych.currentTrial();
var trial_opt_data = typeof trial.data == 'function' ? trial.data() : trial.data;
//var trial_opt_data = typeof trial.data == 'function' ? trial.data() : trial.data;
var default_data = {
'trial_type': trial.type,
@ -626,7 +623,7 @@
'internal_chunk_id': jsPsych.currentChunkID()
};
var ext_data_object = $.extend({}, data_object, trial_opt_data, default_data, dataProperties);
var ext_data_object = $.extend({}, data_object, trial.data, default_data, dataProperties);
allData.push(ext_data_object);
@ -1366,7 +1363,6 @@
var keys = getKeys(trial);
var tmp = {};
for (var i = 0; i < keys.length; i++) {
var process = true;
@ -1378,14 +1374,12 @@
}
if (typeof trial[keys[i]] == "function" && process) {
tmp[keys[i]] = trial[keys[i]].call();
} else {
tmp[keys[i]] = trial[keys[i]];
trial[keys[i]] = trial[keys[i]].call();
}
}
return tmp;
return trial;
};

View File

@ -20,7 +20,7 @@
choices: [89,78], // Y or N
prompt: '<p class="center-content">Have you seen this face before? Y or N.</p>',
data: {trial_data: true},
timing_post_trial: function() { return Math.floor(Math.random()*10000 + 250) }
timing_post_trial: function() { return Math.floor(Math.random()*1000 + 250) }
}
function start(){