You can just write the object as below:
window.a = {
b: {
c: {
d: {
}
}
}
};
But when you want to make this on existent objects, it's better to write a function.
Example:
/**
* Create object(s) in a object.
*
* @param object obj
* @param array path
*/
function createObjectPath(obj, path) {
var currentPath = obj;
// Iterate objects in path
for(var i = 0, p; p = path[i]; i++) {
// Check if doesn't exist the object in current path
if(typeof currentPath[p] !== 'object') {
currentPath[p] = {};
}
currentPath = currentPath[p];
}
}
And you could use this function so:
createObjectPath(window, ['a', 'b', 'c', 'd']);
The function creates a reference of a argumented object in 1st parameter, then iterate over each string in the array argumented in the 2nd parameter and set each string as a object case doesn't exist in a parent object.