I've stripped most of the code and comments from what follows.
My question is about the style that it is written in, not about the correctness of the code itself.
In particular, I've never seen anyone use this way of defining and initializing variables.
The idea is to keep all the definitions together, but to attach and isolate the initialization code for each variable. Ideally each section does nothing but initialize the named variable, with no side effects on anything else.
It works well for me, but want to know whether other people would find it too confusing.
"use strict"
if (typeof RB === 'undefined') var RB = {}
RB.tab = (function() {
let tab_start = function(id, color1="#EFE", color2="#CDC", foldername="...") {
let tabs = document.createElement("div"); {
tabs.setAttribute("id", "tab_" + id)
}
let folder = document.getElementById(id); {
folder.parentNode.insertBefore(tabs, folder)
folder.appendChild(document.createElement("div"))
folder.lastElementChild.innerHTML = "<span></span>" + foldername
}
let c1, c2; {
let get_rgb = function(color) {
let value; {
let temp = document.createElement("div")
document.body.appendChild(temp)
temp.style.color = color
value = window.getComputedStyle(temp).getPropertyValue("color")
document.body.removeChild(temp)
}
return value.substring(4, value.length-1).replace(/ /g, '').split(',')
}
c1 = get_rgb(color1)
c2 = get_rgb(color2)
}
...
}
...
return function(arg) {// RB.tab([ [id, color, color],...,[id, color, color] ])
let url = new URL(location.href)
...
window.onresize()
}
}())