Skip to content

Instantly share code, notes, and snippets.

@DefectingCat
Last active April 21, 2022 08:06
Show Gist options
  • Save DefectingCat/78a914a0a1e893cce2813b274b99c9db to your computer and use it in GitHub Desktop.
Save DefectingCat/78a914a0a1e893cce2813b274b99c9db to your computer and use it in GitHub Desktop.
访问器属性与私有化变量
let xfy = (() => {
let name = 'xfy';
let age = 18;
let obj = {};
Object.defineProperty(obj, 'test', {
get: function () {
return name + ' : ' + age;
},
set: function (value) {
name = value;
age++;
}
})
return obj;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment