Value objects: roll your own?

Brendan Eich brendan at
Sat Jan 11 21:19:26 PST 2014

Axel Rauschmayer wrote:
> One thing is not entirely clear from the slides: Will developers be 
> able to define their own value object types? Without that feature I 
> don’t see how overloading operators would be very interesting.

That is out of date compared to

specifically slide 15:

which has:

value class point2d { // implies typeof “point2d”
   constructor point2d(x, y) {
     this.x = +x;
     this.y = +y;
     // implicit Object.freeze(this) on return
   point2d + number (a, b) {
     return point2d(a.x + b, a.y + b);
   number + point2d (a, b) {
     return point2d(a + b.x, a + b.y);
   point2d + point2d (a, b) {
     return point2d(a.x + b.x, a.y + b.y);
   // more operators, suffix declaration handler, etc.

The idea is to provide convenient declartive syntax for operator 
multimethods that dispatch along the lines proposed by Christian Hansen. 
Some work required to handle subclassing, Christian has been helping, 
writing it up is on my plate for this month.


More information about the es-discuss mailing list