var x = new y ('hello');
function y (mes){
this.mes = mes;
//x.mes = mes;
//Why using object name will not work, with this it will work.
//please read the description what i am trying to ask.
}
Explanation of the problem
I am learning Javascript, From MDN,
I am on the topic working with Object. link is https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects
I am on the topic Using Object Constructor Function
In here they are basically saying if you want to create similar object use this object constructor function.
First I notice they are using keyword this in the function code. I was kinda confuse, than I google it why they are using this keyword instead of simply using variable.
Than it kinda make sense, as what I understood by my google search is this, that this keyword is refer to the object means object which I am initiating with the keyword new,
so I thought I should be able to use object name directly instead of using the this.
I will just initiate the object before the function, and than I should be able to use the object name, and it did not work.
(I am aware if I do this, it actually defeat the purpose of using Object Constructor Function, but that not the point is, the point is do I understand what this means in this context or why it did not work.)
xis not fully defined/initialized until afteryreturns, but you're trying to access it whileystill runs.