delete 연산자를 사용하여 getter를 삭제하려면 delete 키워드를 사용하십시오. 삭제 방법은 다음과 같습니다. −
delete obj.name
예
다음 코드를 실행하여 getter를 삭제하는 방법을 배울 수 있습니다.
라이브 데모
<html> <body> <script> var department = { deptName: "Marketing", deptZone: "North", deptID: 101, get details() { return "Department Details<br>" + "Name: " + this.deptName + " <br>Zone: " + this.deptZone + "<br>ID: " + this.deptID; }, set details(info) { var res = info.toString().split(' '); this.deptName = res[0] || ''; this.deptZone = res[1] || ''; this.deptID = res[2] || ''; } } department.details = 'Marketing North 001'; document.write("<br>Department Name: " + department.deptName); document.write("<br>Departmet Zone: " + department.deptZone); document.write("<br>Department ID: " + department.deptID); delete department.deptName; document.write("<br>Department Name (after deletion): " + department.deptName); </script> </body> </html>