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);
|
this.data.write(data);
|
||||||
|
|
||||||
// get back the data with all of the defaults in
|
// 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
|
// for trial-level callbacks, we just want to pass in a reference to the values
|
||||||
// of the DataCollection, for easy access and editing.
|
// 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;
|
const current_trial = this.current_trial;
|
||||||
|
|
||||||
if (typeof current_trial.save_trial_parameters == "object") {
|
if (typeof current_trial.save_trial_parameters == "object") {
|
||||||
var keys = Object.keys(current_trial.save_trial_parameters);
|
for (const key of Object.keys(current_trial.save_trial_parameters)) {
|
||||||
for (var i = 0; i < keys.length; i++) {
|
const key_val = current_trial.save_trial_parameters[key];
|
||||||
var key_val = current_trial.save_trial_parameters[keys[i]];
|
|
||||||
if (key_val === true) {
|
if (key_val === true) {
|
||||||
if (typeof current_trial[keys[i]] == "undefined") {
|
if (typeof current_trial[key] == "undefined") {
|
||||||
console.warn(
|
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") {
|
} else if (typeof current_trial[key] == "function") {
|
||||||
trial_data_values[keys[i]] = current_trial[keys[i]].toString();
|
trial_data_values[key] = current_trial[key].toString();
|
||||||
} else {
|
} else {
|
||||||
trial_data_values[keys[i]] = current_trial[keys[i]];
|
trial_data_values[key] = current_trial[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (key_val === false) {
|
if (key_val === false) {
|
||||||
// we don't allow internal_node_id or trial_index to be deleted because it would break other things
|
// 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") {
|
if (key !== "internal_node_id" && key !== "trial_index") {
|
||||||
delete trial_data_values[keys[i]];
|
delete trial_data_values[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -260,7 +259,9 @@ export class JsPsych {
|
|||||||
// handle extension callbacks
|
// handle extension callbacks
|
||||||
if (Array.isArray(current_trial.extensions)) {
|
if (Array.isArray(current_trial.extensions)) {
|
||||||
for (const extension of 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);
|
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 undefined, then jsPsych will use the <body> tag and the entire page
|
||||||
if (typeof options.display_element === "undefined") {
|
if (typeof options.display_element === "undefined") {
|
||||||
// check if there is a body element on the page
|
// check if there is a body element on the page
|
||||||
var body = document.querySelector("body");
|
const body = document.querySelector("body");
|
||||||
if (body === null) {
|
if (body === null) {
|
||||||
document.documentElement.appendChild(document.createElement("body"));
|
document.documentElement.appendChild(document.createElement("body"));
|
||||||
}
|
}
|
||||||
@ -489,7 +490,7 @@ export class JsPsych {
|
|||||||
|
|
||||||
// advance timeline
|
// advance timeline
|
||||||
this.timeline.markCurrentTrialComplete();
|
this.timeline.markCurrentTrialComplete();
|
||||||
var complete = this.timeline.advance();
|
const complete = this.timeline.advance();
|
||||||
|
|
||||||
// update progress bar if shown
|
// update progress bar if shown
|
||||||
if (this.opts.show_progress_bar === true && this.opts.auto_update_progress_bar == true) {
|
if (this.opts.show_progress_bar === true && this.opts.auto_update_progress_bar == true) {
|
||||||
@ -636,29 +637,28 @@ export class JsPsych {
|
|||||||
}
|
}
|
||||||
// arrays
|
// arrays
|
||||||
else if (Array.isArray(obj)) {
|
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);
|
obj[i] = this.replaceFunctionsWithValues(obj[i], info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// objects
|
// objects
|
||||||
else if (typeof obj === "object") {
|
else if (typeof obj === "object") {
|
||||||
var keys = Object.keys(obj);
|
|
||||||
if (info == null || !info.nested) {
|
if (info == null || !info.nested) {
|
||||||
for (var i = 0; i < keys.length; i++) {
|
for (const key of Object.keys(obj)) {
|
||||||
if (keys[i] === "type") {
|
if (key === "type") {
|
||||||
// Ignore the object's `type` field because it contains a plugin and we do not want to
|
// Ignore the object's `type` field because it contains a plugin and we do not want to
|
||||||
// call plugin functions
|
// call plugin functions
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
obj[keys[i]] = this.replaceFunctionsWithValues(obj[keys[i]], null);
|
obj[key] = this.replaceFunctionsWithValues(obj[key], null);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (var i = 0; i < keys.length; i++) {
|
for (const key of Object.keys(obj)) {
|
||||||
if (
|
if (
|
||||||
typeof info.nested[keys[i]] == "object" &&
|
typeof info.nested[key] == "object" &&
|
||||||
info.nested[keys[i]].type !== ParameterType.FUNCTION
|
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) {
|
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
|
// check if parameter is complex with nested defaults
|
||||||
if (trial.type.info.parameters[param].type == ParameterType.COMPLEX) {
|
if (trial.type.info.parameters[param].type == ParameterType.COMPLEX) {
|
||||||
if (trial.type.info.parameters[param].array == true) {
|
if (trial.type.info.parameters[param].array == true) {
|
||||||
// iterate over each entry in the array
|
// iterate over each entry in the array
|
||||||
trial[param].forEach(function (ip, i) {
|
trial[param].forEach(function (ip, i) {
|
||||||
// check each parameter in the plugin description
|
// 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[param][i][p] == "undefined" || trial[param][i][p] === null) {
|
||||||
if (typeof trial.type.info.parameters[param].nested[p].default == "undefined") {
|
if (typeof trial.type.info.parameters[param].nested[p].default == "undefined") {
|
||||||
console.error(
|
console.error(
|
||||||
@ -772,7 +772,7 @@ export class JsPsych {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private updateProgressBar() {
|
private updateProgressBar() {
|
||||||
var progress = this.progress().percent_complete;
|
const progress = this.progress().percent_complete;
|
||||||
this.setProgressBar(progress / 100);
|
this.setProgressBar(progress / 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user