aboutsummaryrefslogtreecommitdiff
path: root/files/ko/web/javascript/reference/global_objects/object/__definegetter__/index.html
blob: 2ded710fdaae600f657c0db9542f1cb2984415b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
---
title: Object.prototype.__defineGetter__()
slug: Web/JavaScript/Reference/Global_Objects/Object/__defineGetter__
translation_of: Web/JavaScript/Reference/Global_Objects/Object/__defineGetter__
---
<div>{{JSRef}}</div>

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

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

<h2 id="문법">문법</h2>

<pre class="syntaxbox"><var>obj</var>.__defineGetter__(<var>prop</var>, <var>func</var>)</pre>

<h3 id="인자">인자</h3>

<dl>
 <dt><code>prop</code></dt>
 <dd>함수와 바인드된 프로퍼티의 이름을 나타내는 문자열</dd>
 <dt><code>func</code></dt>
 <dd>프로퍼티 값이 조회되었을 때 호출되는 함수</dd>
</dl>

<h3 id="리턴_값">리턴 값</h3>

<p>{{jsxref("undefined")}}.</p>

<h2 id="Description">Description</h2>

<p><code>__defineGetter__</code> 를 사용하여 기존 오브젝트의 {{jsxref("Operators/get", "getter", "", 1)}}를 사용할 수 있습니다.</p>

<h2 id="Examples">Examples</h2>

<pre class="brush: 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
</pre>

<h2 id="Specifications">Specifications</h2>

<table class="spectable standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('ESDraft', '#sec-object.prototype.__defineGetter__', 'Object.prototype.__defineGetter__()')}}</td>
   <td>{{Spec2('ESDraft')}}</td>
   <td>Included in the (normative) annex for additional ECMAScript legacy features for Web browsers (note that the specification codifies what is already in implementations).</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<div>


<p>{{Compat("javascript.builtins.Object.defineGetter")}}</p>
</div>

<h2 id="See_also">See also</h2>

<ul>
 <li>{{jsxref("Object.prototype.__defineSetter__()")}}</li>
 <li>{{jsxref("Operators/get", "get")}} operator</li>
 <li>{{jsxref("Object.defineProperty()")}}</li>
 <li>{{jsxref("Object.prototype.__lookupGetter__()")}}</li>
 <li>{{jsxref("Object.prototype.__lookupSetter__()")}}</li>
 <li><a href="/en-US/docs/Web/JavaScript/Guide/Working_with_Objects#Defining_getters_and_setters">JS Guide: Defining Getters and Setters</a></li>
 <li><a href="https://whereswalden.com/2010/04/16/more-spidermonkey-changes-ancient-esoteric-very-rarely-used-syntax-for-creating-getters-and-setters-is-being-removed/">[Blog Post] Deprecation of __defineGetter__ and __defineSetter__</a></li>
 <li>{{bug(647423)}}</li>
</ul>