Visit Mozilla.org

JS SetPrototype

From MDC

Set a JavaScript object's prototype.

[edit] Syntax

JSBool JS_SetPrototype(JSContext *cx, JSObject *obj, JSObject *proto);
Name Type Description
cx JSContext * The context in which to set the object's prototype.

Requires request. (In a JS_THREADSAFE build, the caller must be in a request on this JSContext.)

obj JSObject * The object to modify.
proto JSObject * The object to set as the new prototype of obj.

[edit] Description

JS_SetPrototype sets the prototype object for a specified object. A prototype object provides properties that are shared by similar JS object instances. Ordinarily you set a prototype for an object when you create the object with JS_NewObject, but if you do not set a prototype at that time, you can later call JS_SetPrototype to do so.

obj is a pointer to an existing JS object, and proto is a pointer to second existing object upon which the first object is to be based.

On success, JS_SetPrototype returns JS_TRUE. Otherwise it returns JS_FALSE.

Take care not to create a circularly-linked list of prototypes using this function, because such a set of prototypes cannot be resolved by the JavaScript engine and can easily lead to an infinite loop.

To get an object's prototype, use JS_GetPrototype.

LXR ID Search