done = function(data){
        return_val = data;
        end_trial();    
      }
jspsych-call-function
plugin for calling an arbitrary function during a jspsych experiment
Josh de Leeuw

documentation: docs.jspsych.org