Last active
December 21, 2021 03:31
-
-
Save dongyuwei/5d1bc66c10f10c7b6e822d82f03ab741 to your computer and use it in GitHub Desktop.
use Object.defineProperty to do data-binding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
about IE browser support, see https://msdn.microsoft.com/zh-cn/library/dd548687(v=vs.94).aspx