function assign(obj, prop, value) { if (typeof prop === "string") prop = prop.split("."); if (prop.length > 1) { var e = prop.shift(); assign(obj[e] = Object.prototype.toString.call(obj[e]) === "[object Object]" ? obj[e] : {}, prop, value); } else obj[prop[0]] = value;}var obj = {}, propName = "foo.bar.foobar";assign(obj, propName, "Value");
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)