初始化

This commit is contained in:
yziiy
2025-08-11 11:06:07 +08:00
parent 083bc37c00
commit 5607d11395
19772 changed files with 3108723 additions and 18 deletions

View File

@@ -0,0 +1,26 @@
var castPath = require('./castPath');
var isStr = require('./isStr');
var isObj = require('./isObj');
var each = require('./each');
exports = function(obj, prop, descriptor) {
if (isStr(prop)) {
defineProp(obj, prop, descriptor);
} else if (isObj(prop)) {
each(prop, function(descriptor, prop) {
defineProp(obj, prop, descriptor);
});
}
return obj;
};
function defineProp(obj, prop, descriptor) {
var path = castPath(prop, obj);
var lastProp = path.pop();
while ((prop = path.shift())) {
if (!obj[prop]) obj[prop] = {};
obj = obj[prop];
}
Object.defineProperty(obj, lastProp, descriptor);
}
module.exports = exports;