Contents

JSClassDefinition

A structure that contains properties and callbacks that define a type of object.

Declaration

struct JSClassDefinition

Overview

All fields other than the version field are optional. Any pointer may be NULL.

The staticValues and staticFunctions arrays are the simplest and most efficient means for vending custom properties. Statically declared properties automatically service requests like getProperty, setProperty, and getPropertyNames. Property access callbacks are necessary only to implement unusual properties, like array indexes, which have unknown names at compile time.

If you name your getter function GetX and your setter function SetX, you declare a JSStaticValue array that contains "X" like this:

JSStaticValue StaticValueArray[] = { 
    { "X", GetX, SetX, kJSPropertyAttributeNone }, 
    { 0, 0, 0, 0 } 
};

Standard JavaScript practice calls for storing function objects in prototypes so you can share them. The default JSClassRef that JSClassCreate(_:) creates follows this idiom, instantiating objects with a shared, automatically generating prototype that contains the class’s function objects. The kJSClassAttributeNoAutomaticPrototype attribute specifies that a JSClassRef doesn’t automatically generate such a prototype. The resulting JSClassRef instantiates objects with the default object prototype, and gives each instance object its own copy of the class’s function objects.

A NULL callback specifies that the default object callback substitutes, except in the case of hasProperty, where it specifies that getProperty substitutes.

Topics

Creating a Class Definition

Managing Class Information

Managing Callbacks

See Also

Working with Classes