Last active
April 21, 2022 08:06
-
-
Save DefectingCat/78a914a0a1e893cce2813b274b99c9db to your computer and use it in GitHub Desktop.
访问器属性与私有化变量
This file contains 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
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