Value objects: roll your own?

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


Axel Rauschmayer wrote:
> http://www.slideshare.net/BrendanEich/value-objects
>
> 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


http://www.slideshare.net/BrendanEich/js-resp

specifically slide 15:

http://image.slidesharecdn.com/jsresp-130914140214-phpapp02/95/slide-15-638.jpg?1379296961

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.

/be



More information about the es-discuss mailing list