function bindModelInput(obj, property, domElem) { Object.defineProperty(obj, property, { get: function() { return domElem.value; }, set: function(newValue) { domElem.value = newValue; }, configurable: true }); }
// user = {} bindModelInput(user,’name’,document.getElementById(‘foo’)); //hey presto, we now have two-way data binding.
双向绑定的方式: * 数据–> 界面 :Object.observe, es6 proxy, 界面 –> 数据:change * 数据–> 界面 :界面 –> 数据:Object.defineProperty(http://kangax.github.io/compat-table/es5/#Object.defineProperty)