mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 19:20:55 +00:00
replace var with let or const
This commit is contained in:
parent
2b82cab264
commit
c20b2dad49
@ -226,33 +226,32 @@ export class JsPsych {
|
||||
this.data.write(data);
|
||||
|
||||
// get back the data with all of the defaults in
|
||||
var trial_data = this.data.get().filter({ trial_index: this.global_trial_index });
|
||||
let trial_data = this.data.get().filter({ trial_index: this.global_trial_index });
|
||||
|
||||
// for trial-level callbacks, we just want to pass in a reference to the values
|
||||
// of the DataCollection, for easy access and editing.
|
||||
var trial_data_values = trial_data.values()[0];
|
||||
let trial_data_values = trial_data.values()[0];
|
||||
|
||||
const current_trial = this.current_trial;
|
||||
|
||||
if (typeof current_trial.save_trial_parameters == "object") {
|
||||
var keys = Object.keys(current_trial.save_trial_parameters);
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
var key_val = current_trial.save_trial_parameters[keys[i]];
|
||||
for (const key of Object.keys(current_trial.save_trial_parameters)) {
|
||||
const key_val = current_trial.save_trial_parameters[key];
|
||||
if (key_val === true) {
|
||||
if (typeof current_trial[keys[i]] == "undefined") {
|
||||
if (typeof current_trial[key] == "undefined") {
|
||||
console.warn(
|
||||
`Invalid parameter specified in save_trial_parameters. Trial has no property called "${keys[i]}".`
|
||||
`Invalid parameter specified in save_trial_parameters. Trial has no property called "${key}".`
|
||||
);
|
||||
} else if (typeof current_trial[keys[i]] == "function") {
|
||||
trial_data_values[keys[i]] = current_trial[keys[i]].toString();
|
||||
} else if (typeof current_trial[key] == "function") {
|
||||
trial_data_values[key] = current_trial[key].toString();
|
||||
} else {
|
||||
trial_data_values[keys[i]] = current_trial[keys[i]];
|
||||
trial_data_values[key] = current_trial[key];
|
||||
}
|
||||
}
|
||||
if (key_val === false) {
|
||||
// we don't allow internal_node_id or trial_index to be deleted because it would break other things
|
||||
if (keys[i] !== "internal_node_id" && keys[i] !== "trial_index") {
|
||||
delete trial_data_values[keys[i]];
|
||||
if (key !== "internal_node_id" && key !== "trial_index") {
|
||||
delete trial_data_values[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -260,7 +259,9 @@ export class JsPsych {
|
||||
// handle extension callbacks
|
||||
if (Array.isArray(current_trial.extensions)) {
|
||||
for (const extension of current_trial.extensions) {
|
||||
var ext_data_values = this.extensions[extension.type.info.name].on_finish(extension.params);
|
||||
const ext_data_values = this.extensions[extension.type.info.name].on_finish(
|
||||
extension.params
|
||||
);
|
||||
Object.assign(trial_data_values, ext_data_values);
|
||||
}
|
||||
}
|
||||
@ -378,7 +379,7 @@ export class JsPsych {
|
||||
// if undefined, then jsPsych will use the <body> tag and the entire page
|
||||
if (typeof options.display_element === "undefined") {
|
||||
// check if there is a body element on the page
|
||||
var body = document.querySelector("body");
|
||||
const body = document.querySelector("body");
|
||||
if (body === null) {
|
||||
document.documentElement.appendChild(document.createElement("body"));
|
||||
}
|
||||
@ -489,7 +490,7 @@ export class JsPsych {
|
||||
|
||||
// advance timeline
|
||||
this.timeline.markCurrentTrialComplete();
|
||||
var complete = this.timeline.advance();
|
||||
const complete = this.timeline.advance();
|
||||
|
||||
// update progress bar if shown
|
||||
if (this.opts.show_progress_bar === true && this.opts.auto_update_progress_bar == true) {
|
||||
@ -636,29 +637,28 @@ export class JsPsych {
|
||||
}
|
||||
// arrays
|
||||
else if (Array.isArray(obj)) {
|
||||
for (var i = 0; i < obj.length; i++) {
|
||||
for (let i = 0; i < obj.length; i++) {
|
||||
obj[i] = this.replaceFunctionsWithValues(obj[i], info);
|
||||
}
|
||||
}
|
||||
// objects
|
||||
else if (typeof obj === "object") {
|
||||
var keys = Object.keys(obj);
|
||||
if (info == null || !info.nested) {
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
if (keys[i] === "type") {
|
||||
for (const key of Object.keys(obj)) {
|
||||
if (key === "type") {
|
||||
// Ignore the object's `type` field because it contains a plugin and we do not want to
|
||||
// call plugin functions
|
||||
continue;
|
||||
}
|
||||
obj[keys[i]] = this.replaceFunctionsWithValues(obj[keys[i]], null);
|
||||
obj[key] = this.replaceFunctionsWithValues(obj[key], null);
|
||||
}
|
||||
} else {
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
for (const key of Object.keys(obj)) {
|
||||
if (
|
||||
typeof info.nested[keys[i]] == "object" &&
|
||||
info.nested[keys[i]].type !== ParameterType.FUNCTION
|
||||
typeof info.nested[key] == "object" &&
|
||||
info.nested[key].type !== ParameterType.FUNCTION
|
||||
) {
|
||||
obj[keys[i]] = this.replaceFunctionsWithValues(obj[keys[i]], info.nested[keys[i]]);
|
||||
obj[key] = this.replaceFunctionsWithValues(obj[key], info.nested[key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -669,14 +669,14 @@ export class JsPsych {
|
||||
}
|
||||
|
||||
private setDefaultValues(trial) {
|
||||
for (var param in trial.type.info.parameters) {
|
||||
for (const param in trial.type.info.parameters) {
|
||||
// check if parameter is complex with nested defaults
|
||||
if (trial.type.info.parameters[param].type == ParameterType.COMPLEX) {
|
||||
if (trial.type.info.parameters[param].array == true) {
|
||||
// iterate over each entry in the array
|
||||
trial[param].forEach(function (ip, i) {
|
||||
// check each parameter in the plugin description
|
||||
for (var p in trial.type.info.parameters[param].nested) {
|
||||
for (const p in trial.type.info.parameters[param].nested) {
|
||||
if (typeof trial[param][i][p] == "undefined" || trial[param][i][p] === null) {
|
||||
if (typeof trial.type.info.parameters[param].nested[p].default == "undefined") {
|
||||
console.error(
|
||||
@ -772,7 +772,7 @@ export class JsPsych {
|
||||
}
|
||||
|
||||
private updateProgressBar() {
|
||||
var progress = this.progress().percent_complete;
|
||||
const progress = this.progress().percent_complete;
|
||||
this.setProgressBar(progress / 100);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user