Skip to content

Instantly share code, notes, and snippets.

@dongyuwei
Last active December 21, 2021 03:31
Show Gist options
  • Save dongyuwei/5d1bc66c10f10c7b6e822d82f03ab741 to your computer and use it in GitHub Desktop.
Save dongyuwei/5d1bc66c10f10c7b6e822d82f03ab741 to your computer and use it in GitHub Desktop.
use Object.defineProperty to do data-binding
var formInputValue = '[email protected]';
var model = {};
Object.defineProperty(model, 'email', {
get: function () {
return formInputValue;
},
set: function (value) {
console.log(value);
formInputValue = value;
}
});
console.assert(model.email === formInputValue);
model.email = '[email protected]';
console.assert(formInputValue === '[email protected]');
@dongyuwei
Copy link
Author

@jerrylau91
Copy link

ViewModel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment