Hi,
I want my code to work well on V8 which uses hidden classes. For hidden classes to work well, properties have to be initialised in the same order, and the easiest way to achieve this is to initialise them in the constructor. This advice was given by the V8 team in this presentation, starting from slides 26-32:
To help write code that does this, is it possible for the compiler to warn/error if you use a property that is either not defined or not initialised in the constructor, something like:
/**
* @constructor
*/
MyClass = function() {
/** @type {number} */
this.foo = 0; // declared and initialized
/** @type {number} */
this.bar; // declared, not initialized
// this.baz neither declared nor initialized
};
/**
*/
MyClass.prototype.xyzzy = function() {
this.foo = 1; // happy, assignment to a declared and initialised property
this.bar = 2; // WARNING: assignment to property 'bar' which is not initialised in constructor
this.baz = 3; // ERROR: assignment to property 'baz' which is neither initialised nor declared in constructor
};
Cheers,
Tom