JSFiddle - React, Tailwind, and code Playground
by xavierm02
HTML
<div id="console"></div>
JavaScript
// possible workaround
( function ( ) {
var instances = [ ],
xs = [ ],
ys = [ ];
function Point( x, y ) {
instances.push( this );
xs.push( x );
ys.push( y );
}
Object.defineProperties( Point.prototype, {
x: {
get: function ( ) {
return xs[ instances.indexOf( this ) ];
},
set: function ( value ) {
xs[ instances.indexOf( this ) ] = parseInt( value );
}
},
y: {
// same here
}
} );
this.Point = Point;
} )( );
// code used for testing
var c = document.getElementById( 'console' );
function log( m ) {
c.appendChild( document.createTextNode( m ) );
c.appendChild( document.createElement( 'br' ) );
}
function assert( b, m ) {
if ( !b ) {
log( m );
}
}
// tests
try {
var p = new Point( 1, 2 );
assert( p.x === 1, 'bad x 1' );
p.x = 2;
assert( p.x === 2, 'bad x 2' );
p.x = '3';
assert( p.x === 3, 'bad x 3' );
} catch ( e ) {
log( e );
}
log( 'Done' );