Object.prototype.__defineGetter__()
경고 :
이 기능은 object initializer 문법 혹은 Object.defineProperty()
API를 사용한 getter 정의가 표준화됨으로써 비표준화되었습니다.
이 기능은 이제까지의 ECMAScript 사양에서만 사용되고 있습니다.
보다 좋은 방법이 있으므로, 이 메소드는 사용하지 말아야합니다.
__defineGetter__
메소드는 오브젝트의 프로퍼티와 함수를 바인드합니다.
프로퍼티의 값이 조회될 때 바인드된 함수가 호출됩니다.
문법
js
obj.__defineGetter__(prop, func);
인자
리턴 값
Description
__defineGetter__
를 사용하여 기존 오브젝트의 getter를 사용할 수 있습니다.
Examples
js
// Non-standard and deprecated way
var o = {};
o.__defineGetter__("gimmeFive", function () {
return 5;
});
console.log(o.gimmeFive); // 5
// Standard-compliant ways
// Using the get operator
var o = {
get gimmeFive() {
return 5;
},
};
console.log(o.gimmeFive); // 5
// Using Object.defineProperty
var o = {};
Object.defineProperty(o, "gimmeFive", {
get: function () {
return 5;
},
});
console.log(o.gimmeFive); // 5
명세서
Specification |
---|
ECMAScript® 2025 Language Specification # sec-object.prototype.__defineGetter__ |
브라우저 호환성
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
__defineGetter__ |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- Deprecated. Not for use in new websites.
- See implementation notes.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.