This code works fine, although what I'm interested in knowing is, if there's a way that works better and is which I prefer better, which it seem to not be working. Is it possible to do it that way, check the second code example in order to comprehend, what I have in mind when I say "preferred way".
code 1
function a(y){this.b=y;};
var ax = new a("oka");
alert(ax.b);
code 2 (preferred way but does not work)
function a(){this.b = alert(y);this.y = y;}
var ax = new a();
ax.y="okay";
ax.b;
Your use of
thisis mostly fine, but the problem is that this line:...calls
alertand assigns its return value tob. If you wantedbto be a function, you'd do:...so:
Side note: The overwhelming convention in JavaScript is to give constructor functions (functions you call via
new) names starting with a capital letter. SoArather thana, for instance.