JS_DeleteProperty2

  • Revision slug: SpiderMonkey/JSAPI_Reference/JS_DeleteProperty2
  • Revision title: JS_DeleteProperty2
  • Revision id: 138467
  • Created:
  • Creator: Jorend
  • Is current revision? No
  • Comment /* Notes */

Revision Content

{{template.Jsapiref()}}

Removes a specified property from an object.

Syntax

JSBool JS_DeleteProperty2(JSContext *cx, JSObject *obj,
    const char *name, jsval *rval);

JSBool JS_DeleteUCProperty2(JSContext *cx, JSObject *obj,
    const jschar *name, size_t namelen, jsval *rval);


Name Type Description
cx JSContext * Pointer to a JS context from which to derive runtime information. {{wiki.template('Jsapi-requires-request')}}
obj JSObject * Object from which to delete a property.
name const char * or const jschar&nsbp;* Name of the property to delete.
namelen size_t (only in JS_DeleteUCProperty2) The length of name in characters; or -1 to indicate that name is null-terminated.
rval jsval * Out parameter. *rval receives the value of the deleted property.

Description

JS_DeleteProperty2 removes a specified property, name, from an object, obj, and stores a pointer to the deleted property in rval. If rval is NULL, the property is deleted. If an object references a property belonging to a prototype, the property reference is removed from the object, but the prototype's property is not deleted. If deletion is successful, JS_DeleteProperty2 returns JS_TRUE. Otherwise it returns JS_FALSE.

JS_DeleteUCProperty2 is the Unicode version of the function.

Notes

Per the ECMA standard, these functions remove read-only properties from objects as long as those properties are not also permanent.

For JavaScript 1.2 and earlier, if JS_DeleteProperty2 or JS_DeleteUCProperty2 fails because the property to be deleted is permanent, it reports the error before returning JS_FALSE. For JavaScript 1.3, the attempt is silently ignored. In both these cases, *rval will receive the value of the property that was not deleted.

To remove all properties from an object, call JS_ClearScope.

See Also

Groups Functions
Documents {{template.LXRSearch("ident", "i", "JS_DeleteProperty2", "LXR ID Search for JS_DeleteProperty2")}} {{template.LXRSearch("ident", "i", "JS_DeleteUCProperty2", "LXR ID Search for JS_DeleteUCProperty2")}}
Entries

JS_AliasProperty, JS_ClearScope, JS_DefineProperty, JS_DefinePropertyWithTinyId, JS_DefineUCProperty, JS_DefineUCPropertyWithTinyId, JS_DeleteProperty, JS_DeleteUCProperty2, JS_GetProperty, JS_GetUCProperty, JS_LookupProperty, JS_LookupUCProperty, JS_PropertyStub, JS_SetProperty, JS_SetUCProperty

Revision Source

<p> 
{{template.Jsapiref()}}
</p><p>Removes a specified property from an object.
</p>
<h2 name="Syntax"> Syntax </h2>
<pre class="eval">JSBool <b>JS_DeleteProperty2</b>(JSContext *cx, JSObject *obj,
    const char *name, jsval *rval);

JSBool <b>JS_DeleteUCProperty2</b>(JSContext *cx, JSObject *obj,
    const jschar *name, size_t namelen, jsval *rval);
</pre>
<p><br>
</p>
<table class="fullwidth-table">
<tbody><tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
<tr>
<td><code>cx</code></td>
<td><code>JSContext *</code></td>
<td>Pointer to a JS context from which to derive runtime information.
{{wiki.template('Jsapi-requires-request')}}</td>
</tr>
<tr>
<td><code>obj</code></td>
<td><code>JSObject *</code></td>
<td>Object from which to delete a property.</td>
</tr>
<tr>
<td><code>name</code></td>
<td><code>const char *</code> <i>or</i> <code>const jschar&amp;nsbp;*</code></td>
<td>Name of the property to delete.</td>
</tr>
<tr>
<td><code>namelen</code></td>
<td><code>size_t</code></td>
<td><i>(only in <code>JS_DeleteUCProperty2</code>)</i> The length of <code>name</code> in characters; or <code>-1</code> to indicate that <code>name</code> is null-terminated.</td>
</tr>
<tr>
<td><code>rval</code></td>
<td><code>jsval *</code></td>
<td>Out parameter.  <code>*rval</code> receives the value of the deleted property.</td>
</tr>
</tbody></table>
<h2 name="Description"> Description </h2>
<p><code>JS_DeleteProperty2</code> removes a specified property, <code>name</code>, from an object, <code>obj</code>, and stores a pointer to the deleted property in <code>rval</code>. If <code>rval</code> is <code>NULL</code>, the property is deleted. If an object references a property belonging to a prototype, the property reference is removed from the object, but the prototype's property is not deleted. If deletion is successful, <code>JS_DeleteProperty2</code> returns <code>JS_TRUE</code>. Otherwise it returns <code>JS_FALSE</code>.
</p><p><code>JS_DeleteUCProperty2</code> is the Unicode version of the function.
</p>
<h3 name="Notes"> Notes </h3>
<p>Per the ECMA standard, these functions remove read-only properties from objects as long as those properties are not also permanent.
</p><p>For JavaScript 1.2 and earlier, if <code>JS_DeleteProperty2</code> or <code>JS_DeleteUCProperty2</code> fails because the property to be deleted is permanent, it reports the error before returning <code>JS_FALSE</code>. For JavaScript 1.3, the attempt is silently ignored. In both these cases, <code>*rval</code> will receive the value of the property that was not deleted.
</p><p>To remove all properties from an object, call <code><a href="en/JS_ClearScope">JS_ClearScope</a></code>.
</p>
<h2 name="See_Also"> See Also </h2>
<table class="fullwidth-table">
<tbody><tr>
<td>Groups</td>
<td><a href="en/JSAPI_Reference#Functions">Functions</a></td>
</tr>
<tr>
<td>Documents</td>
<td>{{template.LXRSearch("ident", "i", "JS_DeleteProperty2", "LXR ID Search for JS_DeleteProperty2")}}</td>
<td>{{template.LXRSearch("ident", "i", "JS_DeleteUCProperty2", "LXR ID Search for JS_DeleteUCProperty2")}}</td>
</tr>
<tr>
<td>Entries</td>
<td>
<p><a href="en/JS_AliasProperty">JS_AliasProperty</a>,
<a href="en/JS_ClearScope">JS_ClearScope</a>,
<a href="en/JS_DefineProperty">JS_DefineProperty</a>,
<a href="en/JS_DefinePropertyWithTinyId">JS_DefinePropertyWithTinyId</a>,
<a href="en/JS_DefineUCProperty">JS_DefineUCProperty</a>,
<a href="en/JS_DefineUCPropertyWithTinyId">JS_DefineUCPropertyWithTinyId</a>,
<a href="en/JS_DeleteProperty">JS_DeleteProperty</a>,
<a href="en/JS_DeleteUCProperty2">JS_DeleteUCProperty2</a>,
<a href="en/JS_GetProperty">JS_GetProperty</a>,
<a href="en/JS_GetUCProperty">JS_GetUCProperty</a>,
<a href="en/JS_LookupProperty">JS_LookupProperty</a>,
<a href="en/JS_LookupUCProperty">JS_LookupUCProperty</a>,
<a href="en/JS_PropertyStub">JS_PropertyStub</a>,
<a href="en/JS_SetProperty">JS_SetProperty</a>,
<a href="en/JS_SetUCProperty">JS_SetUCProperty</a>
</p>
</td>
</tr>
</tbody></table>
Revert to this revision