Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015년 7월.
set 구문은 객체의 속성에 할당을 시도할 때 호출할 함수를 바인딩합니다.
주어진 함수를 바인딩할 속성 이름.
valprop에 할당을 시도한 값.
expressionECMAScript 2015 이후, 주어진 함수를 바인딩할 속성 이름을 구하는 표현식을 사용할 수도 있습니다.
JavaScript의 설정자(setter)를 사용하면 지정한 속성 값의 변경을 시도할 때마다 함수를 호출할 수 있습니다. 설정자는 보통 접근자(getter)와 함께 '유사 속성'을 정의할 때 사용합니다. 어떤 속성에 설정자를 바인딩하는 동시에, 해당 속성이 값도 가지도록 할 수는 없습니다.
set 구문을 이용할 때는 다음 사항을 주의하세요.
설정자의 식별자는 숫자나 문자열일 수 있습니다.
설정자 함수는 최대 한 개의 매개변수만 가질 수 있습니다.
객체 리터럴에서, 같은 속성 키에 다수의 설정자를 바인딩할 수 없습니다.
객체 리터럴에서, 설정자는 데이터 속성과 같은 키를 사용할 수 없습니다.
다음 예제는 객체 language에 유사 속성 current를 생성합니다. current에 값을 할당하면, 해당 값을 log 속성에 저장합니다.
current의 값은 정의하지 않았으므로, 할당이 아니라 접근을 시도하면 undefined만 반환하는 것에 주의하세요.
접근자를 삭제하려면 간단히 delete 연산자를 사용하세요.
이미 존재하는 객체에 설정자를 추가하려면 Object.defineProperty()를 사용하세요.
| ECMAScript® 2027 Language Specification # sec-method-definitions |
Enable JavaScript to view this browser compatibility table.
This page was last modified on 2025년 2월 11일 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.