I just learned about self-referencing objects in this question. This is awesome that people here at StackOverflow know every dark corner of JavaScript.
Today I wanted to use my knowledge and use a self-referencing object in my code but I couldn't make it. I'm trying to make a self referencing object that have different values in different levels. I want every level of my object have the main properties that I'm defining in level one and level two and below have all properties of level two and so on... Let's see what I'm trying to do:
obj is an object that is self referencing, it means obj.obj refer to obj and so on...
I want to have a property in obj.obj but not in obj, like obj.obj.newProp = "myString" and then every level below the level two should have the newProp.
This is the code I wrote that I'm sure is not current!
var obj = {},
obj.obj = obj,
obj.obj.newProp = "myString";
But when I look at obj it contains "myString". How can I prevent obj refering to obj.obj?