JS solution using function closures

if you don't track the os, but the prefix (including 'g') you have slightly shorter, simpler code since you don't need to add the 'g' in the innermost return.