I cannot find an proper example for the love of my life on how to do this or even if this is possible. Based on my pieced together understanding from fragments of exmaples, I have come up with the following structure
var t = function()
{
this.nestedOne = function()
{
this.nest = function()
{
alert("here");
}
}
}
t.nestedOne.nest();
However this is not working (obviously). I would greatly appreciate if someone could point me in the right direction!
That is simply done with:
Your code otherwise doesn’t make sense.
thisinside function doesn’t refer to the function itself, it refers to the object context that the function is invoked in. And you are not even invoking the functions in your code.If I say
obj.func()thenthisinsidefuncwill beobjfor that call. So assigningthis.asd = truewill assigntrueto that object’s"asd"property.If you wanted to do a nested class, it looks very different:
only ClassA can now make instances of ClassB. This should achieve same goals as nested classes in java.