题解 | #根据包名,在指定空间中创建对象#
根据包名,在指定空间中创建对象
http://www.nowcoder.com/practice/a82e035501504cedbe881d08c824a381
可以直接当成单链表做。
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; }