Object.prototype.__defineSetter__()

  • Revision slug: JavaScript/Reference/Global_Objects/Object/defineSetter
  • Revision title: __defineSetter__
  • Revision id: 82233
  • Created:
  • Creator: Mgjbot
  • Is current revision? No
  • Comment robot Adding: [[ja:Core JavaScript 1.5 Reference:Global Objects:Object: defineSetter]] <<langbot>>

Revision Content

Summary

Binds an object's property to a function to be called when an attempt is made to set that property.

Syntax

obj.__defineSetter__(sprop, fun)

Parameters

sprop
a string containing the name of the property to be bound to the given function
fun
a function to be called when there is an attempt to set the specified property. This function takes the form
function (val) { . . . }
val
an alias for the variable that holds the value attempted to be assigned to prop

Description

The __defineSetter__ method allows a setter to be defined on a pre-existing object.

See also

{{ wiki.languages( { "ja": "ja/Core_JavaScript_1.5_Reference/Global_Objects/Object/defineSetter" } ) }}

Revision Source

<p>
</p>
<h3 name="Summary"> Summary </h3>
<p>Binds an object's property to a function to be called when an attempt is made to set that property.
</p>
<h3 name="Syntax"> Syntax </h3>
<p><code><i>obj</i>.__defineSetter__(<i>sprop</i>, <i>fun</i>)</code>
</p>
<h3 name="Parameters"> Parameters </h3>
<dl><dt> <code>sprop</code>
</dt><dd> a string containing the name of the property to be bound to the given function
</dd></dl>
<dl><dt> <code>fun</code>
</dt><dd> a function to be called when there is an attempt to set the specified property. This function takes the form
</dd><dd> <code>function (<i>val</i>) { . . . }</code>
<dl><dt> <code>val</code>
</dt><dd> an alias for the variable that holds the value attempted to be assigned to <code>prop</code>
</dd></dl>
</dd></dl>
<h3 name="Description"> Description </h3>
<p>The <code>__defineSetter__</code> method allows a <a href="en/Core_JavaScript_1.5_Reference/Operators/Special_Operators/set_Operator">setter</a> to be defined on a pre-existing object.
</p>
<h3 name="See_also"> See also </h3>
<ul><li> <a href="en/Core_JavaScript_1.5_Reference/Operators/Special_Operators/set_Operator">set</a>
</li><li> <a href="en/Core_JavaScript_1.5_Reference/Global_Objects/Object/lookupSetter">__lookupSetter__</a>
</li><li> <a href="en/Core_JavaScript_1.5_Guide/Creating_New_Objects/Defining_Getters_and_Setters">JS Guide:Defining Getters and Setters</a>
</li></ul>
<div class="noinclude">
</div>
{{ wiki.languages( { "ja": "ja/Core_JavaScript_1.5_Reference/Global_Objects/Object/defineSetter" } ) }}
Revert to this revision