可以直接当成单链表做。
function namespace(oNamespace, sPackage) { let obj = sPackage.split('.'); let curr = oNamespace; for (let x of obj){ if (curr[x] !== undefined){ curr = curr[x]; } else { curr[x] = {}; curr = curr[x]; } } return oNamespace; }
可以直接当成单链表做。
function namespace(oNamespace, sPackage) { let obj = sPackage.split('.'); let curr = oNamespace; for (let x of obj){ if (curr[x] !== undefined){ curr = curr[x]; } else { curr[x] = {}; curr = curr[x]; } } return oNamespace; }