// AS-IS
let beforeObj = {
status: {
bfName: 'node',
bfCount: 5
},
getBeforeObj: function () {
this.status.bfCount--;
return this.status.bfCount;
}
};
let getBeforeObj = beforeObj.getBeforeObj;
let bfCount = beforeObj.status.bfCount;
// TO-BE : 객체의 속성을 같은 이름의 변수에 대입
let afterObj = {
status: {
afName: 'node',
afCount: 5
},
getAfterObj() {
this.status.afCount--;
return this.status.afCount;
}
};
let { getAfterObj, status: { afCount } } = afterObj;
console.log('getBeforeObj', getBeforeObj);
console.log('bfCount', bfCount);
console.log('getAfterObj', getAfterObj);
console.log('afCount', afCount);
Ly8gQVMtSVMKbGV0IGJlZm9yZU9iaiA9IHsKCXN0YXR1czogewoJCWJmTmFtZTogJ25vZGUnLAoJCWJmQ291bnQ6IDUKCX0sCglnZXRCZWZvcmVPYmo6IGZ1bmN0aW9uICgpIHsKCQl0aGlzLnN0YXR1cy5iZkNvdW50LS07CgkJcmV0dXJuIHRoaXMuc3RhdHVzLmJmQ291bnQ7Cgl9Cn07CgpsZXQgZ2V0QmVmb3JlT2JqID0gYmVmb3JlT2JqLmdldEJlZm9yZU9iajsKbGV0IGJmQ291bnQgPSBiZWZvcmVPYmouc3RhdHVzLmJmQ291bnQ7CgoKLy8gVE8tQkUgOiDqsJ3ssrTsnZgg7IaN7ISx7J2EIOqwmeydgCDsnbTrpoTsnZgg67OA7IiY7JeQIOuMgOyehQpsZXQgYWZ0ZXJPYmogPSB7CglzdGF0dXM6IHsKCQlhZk5hbWU6ICdub2RlJywKCQlhZkNvdW50OiA1Cgl9LAoJZ2V0QWZ0ZXJPYmooKSB7CgkJdGhpcy5zdGF0dXMuYWZDb3VudC0tOwoJCXJldHVybiB0aGlzLnN0YXR1cy5hZkNvdW50OwoJfQp9OwoKbGV0IHsgZ2V0QWZ0ZXJPYmosIHN0YXR1czogeyBhZkNvdW50IH0gfSA9IGFmdGVyT2JqOwoKCmNvbnNvbGUubG9nKCdnZXRCZWZvcmVPYmonLCBnZXRCZWZvcmVPYmopOwpjb25zb2xlLmxvZygnYmZDb3VudCcsIGJmQ291bnQpOwoKY29uc29sZS5sb2coJ2dldEFmdGVyT2JqJywgZ2V0QWZ0ZXJPYmopOwpjb25zb2xlLmxvZygnYWZDb3VudCcsIGFmQ291bnQpOwo=