variables in javascript (and in every other language) are just memory slots that hold values. (a + b) is a right hand expression, that is evaluated, then this.c is set to the value of its result at runtime. Once execution of that code line is complete, the only thing that remains is the variable c with a single integer value. Even if you wrote something like this:
var x = 1;
var y = x;
y would only be set to the value of x at the time the declaration occurs. now you could set x to whatever you want, y will remain 1 until you explicitly change it. If you think about it, this makes sense in most cases. However, there are cases where you would infact want c to represent a dynamic expression, in which case you could use a function as someone as already described:
A.prototype.c = function(){
return this.a + this.b;
};
now if you call ia.c() it will return the value of ia.a + ia.b at the time that function call is made.
Maybe you're going for something a bit fancier, and you don't want to use function call syntax, in which case you could use javascript getters/setters:
this.c = {
get:function(){
return this.a + this.b;
}
}
Now, any time you use this.c in an expression, this function will be invoked, and this.c will be set to the result. The above is not common or standard though. I absolutely would avoid it. Such a feature is absent in most programming languages, and goes against good design practices. An explicit function call is the right way to retrieve the value of dynamic expressions at run-time.
cis set in your constructor, but you are settingaandbafter the constructor has run.