<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.5.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "JavaScriptCore",
  "identifier" : "/documentation/JavaScriptCore/JSClassDefinition",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "JavaScriptCore"
    ],
    "preciseIdentifier" : "c:@SA@JSClassDefinition"
  },
  "title" : "JSClassDefinition"
}
-->

# JSClassDefinition

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

```
struct JSClassDefinition
```

## Overview

All fields other than the [`version`](/documentation/JavaScriptCore/JSClassDefinition/version) field are optional. Any pointer may be `NULL`.

The [`staticValues`](/documentation/JavaScriptCore/JSClassDefinition/staticValues) and [`staticFunctions`](/documentation/JavaScriptCore/JSClassDefinition/staticFunctions) arrays are the simplest and most efficient means for vending custom properties. Statically declared properties automatically service requests like [`getProperty`](/documentation/JavaScriptCore/JSClassDefinition/getProperty), [`setProperty`](/documentation/JavaScriptCore/JSClassDefinition/setProperty), and [`getPropertyNames`](/documentation/JavaScriptCore/JSClassDefinition/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`](/documentation/JavaScriptCore/JSStaticValue) array that contains `"X"` like this:

```c
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`](/documentation/JavaScriptCore/JSClassRef) that [`JSClassCreate(_:)`](/documentation/JavaScriptCore/JSClassCreate(_:)) creates follows this idiom, instantiating objects with a shared, automatically generating prototype that contains the class’s function objects. The [`kJSClassAttributeNoAutomaticPrototype`](/documentation/JavaScriptCore/kJSClassAttributeNoAutomaticPrototype) attribute specifies that a [`JSClassRef`](/documentation/JavaScriptCore/JSClassRef) doesn’t automatically generate such a prototype. The resulting [`JSClassRef`](/documentation/JavaScriptCore/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`](/documentation/JavaScriptCore/JSClassDefinition/hasProperty), where it specifies that [`getProperty`](/documentation/JavaScriptCore/JSClassDefinition/getProperty) substitutes.

## Topics

### Creating a Class Definition

[`init()`](/documentation/JavaScriptCore/JSClassDefinition/init())

Creates an empty class definition.

[`init(version:attributes:className:parentClass:staticValues:staticFunctions:initialize:finalize:hasProperty:getProperty:setProperty:deleteProperty:getPropertyNames:callAsFunction:callAsConstructor:hasInstance:convertToType:)`](/documentation/JavaScriptCore/JSClassDefinition/init(version:attributes:className:parentClass:staticValues:staticFunctions:initialize:finalize:hasProperty:getProperty:setProperty:deleteProperty:getPropertyNames:callAsFunction:callAsConstructor:hasInstance:convertToType:))

Creates a class definition with the specified values.

[`JSClassAttributes`](/documentation/JavaScriptCore/JSClassAttributes)

A set of JavaScript class attributes.

### Managing Class Information

[`parentClass`](/documentation/JavaScriptCore/JSClassDefinition/parentClass)

A JavaScript class to set as the class’s parent class.

[`className`](/documentation/JavaScriptCore/JSClassDefinition/className)

A null-terminated UTF-8 string that contains the class’s name.

[`version`](/documentation/JavaScriptCore/JSClassDefinition/version)

The version of the class definition structure.

[`attributes`](/documentation/JavaScriptCore/JSClassDefinition/attributes)

A set of class attributes to give to the class.

[`staticValues`](/documentation/JavaScriptCore/JSClassDefinition/staticValues)

An array that contains the class’s statically declared value properties.

[`JSStaticValue`](/documentation/JavaScriptCore/JSStaticValue)

A statically declared value property.

[`staticFunctions`](/documentation/JavaScriptCore/JSClassDefinition/staticFunctions)

An array that contains the class’s statically declared function properties.

[`JSStaticFunction`](/documentation/JavaScriptCore/JSStaticFunction)

A statically declared function property.

### Managing Callbacks

[`initialize`](/documentation/JavaScriptCore/JSClassDefinition/initialize)

The callback for creating the object.

[`JSObjectInitializeCallback`](/documentation/JavaScriptCore/JSObjectInitializeCallback)

The callback type for first creating an object.

[`finalize`](/documentation/JavaScriptCore/JSClassDefinition/finalize)

The callback for preparing the object for garbage collection.

[`JSObjectFinalizeCallback`](/documentation/JavaScriptCore/JSObjectFinalizeCallback)

The callback type for finalizing an object (preparing it for garbage collection).

[`hasProperty`](/documentation/JavaScriptCore/JSClassDefinition/hasProperty)

The callback for determining whether an object has a property.

[`JSObjectHasPropertyCallback`](/documentation/JavaScriptCore/JSObjectHasPropertyCallback)

The callback type for determining whether an object has a property.

[`getProperty`](/documentation/JavaScriptCore/JSClassDefinition/getProperty)

The callback for getting a property’s value.

[`JSObjectGetPropertyCallback`](/documentation/JavaScriptCore/JSObjectGetPropertyCallback)

The callback type for getting a property’s value.

[`setProperty`](/documentation/JavaScriptCore/JSClassDefinition/setProperty)

The callback for setting a property’s value.

[`JSObjectSetPropertyCallback`](/documentation/JavaScriptCore/JSObjectSetPropertyCallback)

The callback type for setting a property’s value.

[`deleteProperty`](/documentation/JavaScriptCore/JSClassDefinition/deleteProperty)

The callback for deleting a property.

[`JSObjectDeletePropertyCallback`](/documentation/JavaScriptCore/JSObjectDeletePropertyCallback)

The callback type for deleting a property.

[`getPropertyNames`](/documentation/JavaScriptCore/JSClassDefinition/getPropertyNames)

The callback for collecting the names of an object’s properties.

[`JSObjectGetPropertyNamesCallback`](/documentation/JavaScriptCore/JSObjectGetPropertyNamesCallback)

The callback type for collecting the names of an object’s properties.

[`callAsFunction`](/documentation/JavaScriptCore/JSClassDefinition/callAsFunction)

The callback for calling an object as a function.

[`JSObjectCallAsFunctionCallback`](/documentation/JavaScriptCore/JSObjectCallAsFunctionCallback)

The callback type for calling an object as a function.

[`hasInstance`](/documentation/JavaScriptCore/JSClassDefinition/hasInstance)

The callback for checking whether an object is an instance of a particular type.

[`JSObjectHasInstanceCallback`](/documentation/JavaScriptCore/JSObjectHasInstanceCallback)

The callback type for checking whether an object is an instance of a particular type.

[`callAsConstructor`](/documentation/JavaScriptCore/JSClassDefinition/callAsConstructor)

The callback for using an object as a constructor.

[`JSObjectCallAsConstructorCallback`](/documentation/JavaScriptCore/JSObjectCallAsConstructorCallback)

The callback type for using an object as a constructor.

[`convertToType`](/documentation/JavaScriptCore/JSClassDefinition/convertToType)

The callback for converting an object to a particular JavaScript type.

[`JSObjectConvertToTypeCallback`](/documentation/JavaScriptCore/JSObjectConvertToTypeCallback)

The callback type for converting an object to a particular JavaScript type.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)