const bindFunctionToChart = (fun, str, newobj = {}, split = "_") => {
str.split(split).reduce((total, v, index, array,obj = {}) => {
obj[v] = {};
if ((index + 1) == array.length) {
obj[v] = typeof fun == "function" ? fun.call(array,v) : fun;
}
total!="" && eval(`newobj${total} = obj;`);
return `${total}['${v}']`;
}, "");
return newobj;
}
let str = "a_b_c_d_e_f";
let obj = bindFunctionToChart('2', str);
let obj2 = bindFunctionToChart((v) => `最后一个是 ${v}`, str);
console.log('obj>',JSON.stringify(obj));
console.log('obj2>',JSON.stringify(obj2));