JSFiddle - React, Tailwind, and code Playground

by Derija93

HTML

<pre>Change the value, and the interval will use it.
    
</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;
setInterval(function() {
    obj.value += ++i;
}, 1000);