JSFiddle - React, Tailwind, and code Playground
by xavierm02
HTML
<div id="console"></div>
JavaScript
// possible workaround
function Point( x, y ) {
Object.defineProperties( Point.prototype, {
x: {
get: function ( ) {
return x;
},
set: function ( value ) {
x = parseInt( value, 10 );
}
},
y: {
// same here
}
} );
}
// 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' );