标签:property names test amp json 创建对象 === prope split
namespace({a: {test: 1, b: 2}}, ‘a.b.c.d‘)
{a: {test: 1, b: {c: {d: {}}}}}
function namespace(oNamespace, sPackage) { var a = sPackage.split(‘.‘), o = oNamespace; a.forEach(function(item) { if (!(o.hasOwnProperty(item) && typeof o[item]==="object")) { o[item] = {}; } o = o[item]; }); return oNamespace; } var o = namespace({ a: { test: 1, b: 2 } }, ‘a.b.c.d‘); console.log(o); console.log(JSON.stringify(o)); // {"a":{"test":1,"b":{"c":{"d":{}}}}}
标签:property names test amp json 创建对象 === prope split
原文地址:https://www.cnblogs.com/mingzhanghui/p/9251158.html