This article is in need of a technical review.
Removes a specified property from an object.
bool JS_DeleteProperty(JSContext *cx, JS::HandleObject obj, const char *name); bool JS_DeletePropertyById(JSContext *cx, JS::HandleObject obj, jsid id); // Added in SpiderMonkey 1.8.1 // Added in SpiderMonkey 45 bool JS_DeleteProperty(JSContext *cx, JS::HandleObject obj, const char *name, JS::ObjectOpResult &result); bool JS_DeletePropertyById(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::ObjectOpResult &result); bool JS_DeleteUCProperty(JSContext *cx, JS::HandleObject obj, const char16_t *name, size_t namelen, JS::ObjectOpResult &result);
||Pointer to a JS context from which to derive runtime information. Requires request. In a
||Object from which to delete a property.|
||Name of the property to delete.|
||(out parameter) Receives the result of the operation.|
JS_DeleteProperty removes a specified property,
name, from an object,
JS_DeletePropertyById is the same but takes a
jsid for the property name. These functions are identical to
JS_DeletePropertyById2 except that they do not have an out parameter.
First, a property lookup is performed. Then one of the following cases applies:
objhas no property with the given
id, or if
objinherits the specified property from its prototype, then
JSClass.delPropertyhook is called. No property is deleted, but this is not an error.
objhas the specified property but it is permanent, nothing happens. No property is deleted, but this is not an error.
objhas a non-permanent own property with the given
id. In this case,
JSClass.delPropertyhook is called. If the hook returns
false, the error is propagated. Otherwise, if
objis not configurable, an error is raised. Otherwise, the property is removed.
These functions return
true on success, regardless of whether a property was actually deleted, and
false on error or exception.
Internally, property deletion is implemented by the
To remove all properties from an object, call