Can I write nested classes in Javascript?
function A()
{
this.a;
this.B = function()
{
this.ab ;
this.C = function()
{
this.ab = 0;
}
}
}
If the above code is correct,then
1.How do I declare an object of type B 2.Whose property is ab.A() 's or B() 's?. 3.Inside B() where does the 'this' points to.To A() Or to B()?
Abstract:
Calling to function without using
newoperator means thatthiswill be refer to object in which that function was created.For global variables this object is window object.
Calling using
new– function behave as constructor like in classes andthisrefers to this instance which will been created1.How do I declare an object of type B
First way( as a curiosity ) – by calling to
Awithout usingnewoperatorthiswill be refer towindowobject andBmethod and all other what was declared withthisleaks to global scope becauseA == window.A=>trueor from instance of A:
Be careful.
2.Whose property is ab.A() ‘s or B() ‘s?.
As above, it depends of how we’ll accessing to it:
Check this out
but
3.Inside B() where does the ‘this’ points to.To A() Or to B()?
As above:)