blob: db8cff8ebac35d744f8094f66e90236e28ab0054 (
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
|
---
title: Object.prototype.__lookupSetter__()
slug: Web/JavaScript/Reference/Global_Objects/Object/__lookupSetter__
tags:
- 不建议使用
- 原型
- 对象
- 方法
- 过时的
- 非标准
translation_of: Web/JavaScript/Reference/Global_Objects/Object/__lookupSetter__
---
<div>{{JSRef}} {{deprecated_header}}</div>
<div><code><strong>__lookupSetter__</strong></code> 方法是用来返回一个对象的某个属性上绑定了 setter (设置器)的钩子函数的引用。</div>
<div> </div>
<h2 id="语法">语法</h2>
<pre class="syntaxbox"><code><var>obj</var>.__lookupSetter__(<var>sprop</var>)</code></pre>
<h3 id="参数说明">参数说明</h3>
<dl>
<dt><code>sprop</code></dt>
<dd>一个字符串类型,表示要返回的 setter 钩子的函数名。</dd>
</dl>
<h3 id="返回值">返回值</h3>
<p>一个绑定了setter的特殊属性的函数引用。</p>
<h2 id="描述">描述</h2>
<p>如果一个 setter 被定义在了一个对象的属性上,则不能直接通过该属性来获取引用 setter 所设置的钩子的函数,因为该属性是该函数的返回值,但,__lookupSetter__ 可以被用来获取对 setter 函数的引用。</p>
<p>不过现在可以使用标准的方法:</p>
<p>{{jsxref("Object.getOwnPropertyDescriptor()")}}.</p>
<h2 id="示例">示例</h2>
<pre class="brush: js">var obj = {
set foo(value) {
this.bar = value;
}
};
// 非标准,并且不推荐使用。
obj.__lookupSetter__('foo')
// (function(value) { this.bar = value; })
// 标准且推荐使用的方式。
Object.getOwnPropertyDescriptor(obj, 'foo').set;
// (function(value) { this.bar = value; })
</pre>
<h2 id="规范">规范</h2>
<table class="spectable standard-table">
<tbody>
<tr>
<th scope="col">规范</th>
<th scope="col">状态</th>
<th scope="col">备注</th>
</tr>
<tr>
<td>{{SpecName('ESDraft', '#sec-object.prototype.__lookupSetter__', 'Object.prototype.__lookupSetter__()')}}</td>
<td>{{Spec2('ESDraft')}}</td>
<td>包含在(规范性)附件中,用于Web浏览器的附加ECMAScript遗留功能(请注意,这份规范编撰的内容已经是准备实现的了)。</td>
</tr>
</tbody>
</table>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
{{Compat}}
<h2 id="相关链接">相关链接</h2>
<ul>
<li>{{jsxref("Object.prototype.__lookupGetter__()")}}</li>
<li>{{jsxref("Functions/set", "set")}} operator</li>
<li>{{jsxref("Object.getOwnPropertyDescriptor()")}} and {{jsxref("Object.getPrototypeOf()")}}</li>
<li>{{jsxref("Object.prototype.__defineGetter__()")}}</li>
<li>{{jsxref("Object.prototype.__defineSetter__()")}}</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>
</ul>
|