From dba6c4befc7856f719417ca623eddc1c0110cba9 Mon Sep 17 00:00:00 2001 From: Josh de Leeuw Date: Tue, 8 Dec 2015 10:35:29 -0500 Subject: [PATCH] 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. --- jspsych.js | 18 ++++++------------ tests&examples/timing-post-trial-function.html | 2 +- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/jspsych.js b/jspsych.js index a69eae68..5ffa9c56 100755 --- a/jspsych.js +++ b/jspsych.js @@ -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; }; diff --git a/tests&examples/timing-post-trial-function.html b/tests&examples/timing-post-trial-function.html index b0477ffb..c7eb40e3 100644 --- a/tests&examples/timing-post-trial-function.html +++ b/tests&examples/timing-post-trial-function.html @@ -20,7 +20,7 @@ choices: [89,78], // Y or N prompt: '

Have you seen this face before? Y or N.

', 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(){