mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-10 07:54:06 +08:00
104 lines
6.0 KiB
HTML
104 lines
6.0 KiB
HTML
<article id="wikiArticle">
|
|
<div>
|
|
<div class="blockIndicator nonStandard nonStandardHeader">
|
|
<p><strong><span class="icon-only-inline" title="This API has not been standardized."><i class="icon-warning-sign"> </i></span> 非标准</strong><br/>
|
|
该特性是非标准的,请尽量不要在生产环境中使用它!</p>
|
|
</div> <div class="blockIndicator deprecated deprecatedHeader">
|
|
<p><strong><span class="icon-only-inline" title="This is an obsolete API and is no longer guaranteed to work."><i class="icon-trash"> </i></span> 已废弃</strong><br/>该特性已经从 Web 标准中删除,虽然一些浏览器目前仍然支持它,但也许会在未来的某个时间停止支持,请尽量不要使用该特性。</p>
|
|
</div></div>
|
|
<h2 id="Summary" name="Summary"><span class="def"><span>概述</span></span></h2>
|
|
<p><code><strong>__defineSetter__ </strong>方法可以将一个函数绑定在当前对象的指定属性</code>上,当那个属性被赋值时,你所绑定的函数就会被调用。</p>
|
|
<h2 id="Syntax" name="Syntax">语法</h2>
|
|
<pre><code class="language-javascript"><code><var>obj</var>.__defineSetter__(<var>prop</var>, <var>fun</var>)</code></code></pre>
|
|
<h3 id="Parameters" name="Parameters">参数</h3>
|
|
<dl>
|
|
<dt>
|
|
<code>prop</code></dt>
|
|
<dd>
|
|
一个字符串,表示指定的属性名。</dd>
|
|
<dt>
|
|
<code>fun</code></dt>
|
|
<dd>
|
|
一个函数,当试图去为 <code>sprop</code> 属性赋值时被调用。通常你要给这个函数指定一个参数:<br/>
|
|
<pre>function(<var>val</var>) { . . . }</code></pre>
|
|
<dl>
|
|
<dt>
|
|
<code>val</code></dt>
|
|
<dd>
|
|
任意的参数名,在 fun 被调用时,该参数的值就是尝试给 <code>sprop</code> 属性所赋的值。</dd>
|
|
</dl>
|
|
</dd>
|
|
</dl>
|
|
<h2 id="Description" name="Description">描述</h2>
|
|
<p><code>__defineSetter__</code> 方法可以为一个已经存在的对象设置(新建或修改)访问器属性,而 <a class="new" href="Reference/Operators/set" rel="nofollow" title="此页面仍未被本地化, 期待您的翻译!">对象字面量中的 set 语法</a> 只能在新建一个对象时使用。</p>
|
|
<h2 id="Specifications" name="Specifications">规范</h2>
|
|
<p>不属于任何规范。</p>
|
|
<h2 id="Browser_compatibility" name="Browser_compatibility"><span class="def"><span>浏览器兼容性</span></span></h2>
|
|
<div>
|
|
<div class="blockIndicator warning"><strong><a class="external" href="https://github.com/mdn/browser-compat-data" rel="noopener">We're converting our compatibility data into a machine-readable JSON format</a></strong>.
|
|
This compatibility table still uses the old format,
|
|
because we haven't yet converted the data it contains.
|
|
<strong><a class="new" href="/zh-CN/docs/MDN/Contribute/Structures/Compatibility_tables" rel="nofollow">Find out how you can help!</a></strong></div>
|
|
<div class="htab">
|
|
<a id="AutoCompatibilityTable" name="AutoCompatibilityTable"></a>
|
|
<ul>
|
|
<li class="selected"><a>Desktop</a></li>
|
|
<li><a>Mobile</a></li>
|
|
</ul>
|
|
</div></div>
|
|
<div id="compat-desktop">
|
|
<table class="compat-table">
|
|
<tbody>
|
|
<tr>
|
|
<th>Feature</th>
|
|
<th>Chrome</th>
|
|
<th>Firefox (Gecko)</th>
|
|
<th>Internet Explorer</th>
|
|
<th>Opera</th>
|
|
<th>Safari</th>
|
|
</tr>
|
|
<tr>
|
|
<td>Basic support</td>
|
|
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
|
|
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
|
|
<td>11</td>
|
|
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
|
|
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<div id="compat-mobile">
|
|
<table class="compat-table">
|
|
<tbody>
|
|
<tr>
|
|
<th>Feature</th>
|
|
<th>Android</th>
|
|
<th>Chrome for Android</th>
|
|
<th>Firefox Mobile (Gecko)</th>
|
|
<th>IE Mobile</th>
|
|
<th>Opera Mobile</th>
|
|
<th>Safari Mobile</th>
|
|
</tr>
|
|
<tr>
|
|
<td>Basic support</td>
|
|
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
|
|
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
|
|
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
|
|
<td><span style="color: rgb(255, 153, 0);" title="Compatibility unknown; please update this.">?</span></td>
|
|
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
|
|
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<h2 id="See_also" name="See_also">相关链接</h2>
|
|
<ul>
|
|
<li><a href="Reference/Global_Objects/Object/__defineGetter__" title="__defineGetter__ 方法可以将一个函数绑定在当前对象的指定属性上,当那个属性的值被读取时,你所绑定的函数就会被调用。"><code>Object.prototype.__defineGetter__()</code></a></li>
|
|
<li><a class="new" href="Reference/Operators/set" rel="nofollow" title="此页面仍未被本地化, 期待您的翻译!"><code>set</code></a> operator</li>
|
|
<li><a href="Reference/Global_Objects/Object/defineProperty" title="Object.defineProperty() 方法会直接在一个对象上定义一个新属性,或者修改一个对象的现有属性, 并返回这个对象。"><code>Object.defineProperty()</code></a></li>
|
|
<li><a href="Reference/Global_Objects/Object/__lookupSetter__" title="一个绑定了setter的特殊属性的函数引用。"><code>Object.prototype.__lookupSetter__()</code></a></li>
|
|
<li><a href="Guide/Working_with_Objects#Defining_getters_and_setters">JS 指南: 定义 Getter 和 Setter</a></li>
|
|
<li><a class="external" href="http://whereswalden.com/2010/04/16/more-spidermonkey-changes-ancient-esoteric-very-rarely-used-syntax-for-creating-getters-and-setters-is-being-removed/" rel="noopener">[个人博客] defineGetter__ 和 __defineSetter__</a>已被废弃</li>
|
|
</ul>
|
|
</article> |