JavaScript-1.5 Reference

JS_SetPrototype Function

Summary

Sets the prototype for an object.

Syntax

JSBool JS_SetPrototype(JSContext *cx, JSObject *obj,
    JSObject *proto);
NameTypeDescription
cxJSContext *Pointer to a JS context from which to derive runtime information.
objJSObject *Pointer to the object for which to set the prototype.
protoJSObject *Pointer to the prototype to use.

Description

JS_SetPrototype enables you to set 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 based.

If JS_SetPrototype is successful, it returns JS_TRUE. Otherwise, if it cannot create and fill a prototype slot for the object, it returns JS_FALSE.

Notes

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 JS engine.

See Also

Groups [ Function ]
Documents [ LXR ID Search ]
Entries [ JS_GetPrototype | JS_NewObject ]

This page was generated by APIDOC