JSFiddle - React, Tailwind, and code Playground

by Vipin Goyal

HTML

<pre>Change the value, and the interval will use it.
    It's crap.
</pre>
<input id="foo" value="bar" />

JavaScript

function MyCtor( bindTo ) {
    // I'll omit parameter validation here.
    
    Object.defineProperty(this, 'value', {
        get : function ( ) {
            return bindTo.value;
        },
        set : function ( val ) {
            bindTo.value = val;
        }
    });
}

//var obj = new MyCtor(document.getElementById('foo')), i = 0;
var obj = document.getElementById('foo'),
    i = 0;
setInterval(function() {
    obj.value += ++i;
}, 1000);