It’s difficult to do that if you want your constructors to remain subtypable.
Is the following the best we can do? A constructor can only freeze if it is the
first constructor that is invoked.
function Point(x, y) {
this.x = x;
this.y = y;
if (this.constructor === Point) {
Object.freeze(this);
}
}
function ColorPoint(x, y, color) {
Point.call(this, x, y);
this.color = color;
if (this.constructor === ColorPoint) {
Object.freeze(this);
}
}
ColorPoint.prototype = Object.create(Point);
ColorPoint.prototype.constructor = ColorPoint;
(More detailed write-up: http://www.2ality.com/2013/06/freezing-instances.html )
--
Dr. Axel Rauschmayer
[email protected]
home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss