Object.prototype.__defineGetter__()

경고 : 이 기능은 object initializer 문법 혹은 Object.defineProperty() API를 사용한 getter 정의가 표준화됨으로써 비표준화되었습니다. 이 기능은 이제까지의 ECMAScript 사양에서만 사용되고 있습니다. 보다 좋은 방법이 있으므로, 이 메소드는 사용하지 말아야합니다.

__defineGetter__ 메소드는 오브젝트의 프로퍼티와 함수를 바인드합니다. 프로퍼티의 값이 조회될 때 바인드된 함수가 호출됩니다.

문법

js
obj.__defineGetter__(prop, func);

인자

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 GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
__defineGetter__
Deprecated

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.

See also