All code assumes define strict properties in included upfront.
However, being the proposal fullyt backward compatible, you can tests these snipets by copy and paste but no type will be guarded.
function Point2D(x, y) {
this.x = x;
this.y = y;
}
Object.defineProperties(
Point2D.prototype,
{
x: {
type: 'number',
writable: true
},
y: {
type: 'number',
writable: true
}
}
);
var p = new Point2D(12, 3);
p.x; // 12
p.y; // 3
p.x = '4'; // throws Error: expected number