Typed Objects and Classes

Brian Barnes ggadwa at charter.net
Mon Jun 20 15:20:45 UTC 2016


As far as I can read, Typed Objects/Structs are in consideration for a 
later version of ecmascript (but not in the spec) and there exists some 
implementations.  It depends on the engine, but has there been any 
thought to how costly they might be to fake at least some rudimentary 
type support?  For instance:

class point2D
{
	constructor()
	{
		this.props=new Structure({
			x:uint32,
			y:unit32
		});
	}

	setMe(x,y) {
		this.props.x=x;
		this.props.y=y;
	}
}

This doubles the property lookups but that can probably be optimized 
away (maybe) -- but it does force the engine to consider x/y as always 
ints.  Of course, this doesn't do anything about the function signatures.

I don't think types are coming anytime soon, and just wondering if, in 
the future, messy code like this might be worth it, or otherwise, to let 
implementers know this is something that people might try with their 
code and would be an interesting path to look at.

[>] Brian


More information about the es-discuss mailing list