I am trying to create a dashboard for my classroom (async starting, async duration, async testing)...
My problem is I dynamicly create functions with eval
(I know it's the way to the dark side). Do those dynamic created functions also no longer live then the for
loop who they were created in?
function onOpen() {
const FUNC_STR = 'course';
var evalString = '';
const response = Classroom.Courses.list();
const courses = response.courses;
for(var index in courses) {
const course = courses[index]
evalString += 'function ' + FUNC_STR + course.id + '() { ' + FUNC_STR + '(' + course.id + ') }';
eval(evalString);
}
const ui = SpreadsheetApp.getUi();
var mymenu = ui.createMenu('Classroom');
if (courses && courses.length > 0) {
for (i = 0; i < courses.length; i++) {
const course = courses[i];
mymenu.addItem(course.name, FUNC_STR + course.id);
}
mymenu.addToUi();
}
}
function course(id ) {
SpreadsheetApp.getActiveSheet().getRange('A1').setValue(Classroom.Courses.get(id).name);
}