Creating JavaScript classes

Creating JavaScript classes — Dealing with Seed class definitions and constructors

Synopsis

#include <seed/seed.h>

enum                SeedPropertyAttributes;
enum                SeedClassAttributes;
typedef             SeedClass;
#define             seed_empty_class
SeedClass           seed_create_class                   (seed_class_definition *def);
SeedObject          seed_make_constructor               (SeedContext ctx,
                                                         SeedClass klass,
                                                         SeedObjectCallAsConstructorCallback constructor);

Description

Defining new Seed classes allows for implementing more complex behavior than possible with the traditional JavaScript object system and default class. When writing Seed modules, it is often the best pattern to define many of your types through classes and static functions/value. Please note that inside the finalize callback of a class, it is not legal to call any method requiring a SeedContext (with the exception of protect/unprotect, though it is not guaranteed this will continue to work with future versions of JSCore).

Details

enum SeedPropertyAttributes

typedef enum {
  SEED_PROPERTY_ATTRIBUTE_NONE = 0,
  SEED_PROPERTY_ATTRIBUTE_READ_ONLY = 1 << 1,
  SEED_PROPERTY_ATTRIBUTE_DONT_ENUM = 1 << 2,
  SEED_PROPERTY_ATTRIBUTE_DONT_DELETE = 1 << 3
} SeedPropertyAttributes;


enum SeedClassAttributes

typedef enum {
  SEED_CLASS_ATTRIBUTE_NONE = 0,
  SEED_CLASS_ATTRIBUTE_NO_SHARED_PROTOTYPE = 1 << 1
} SeedClassAttributes;


SeedClass

typedef gpointer SeedClass;


seed_empty_class

#define seed_empty_class { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,};


seed_create_class ()

SeedClass           seed_create_class                   (seed_class_definition *def);

def :

A JSClassDefinition.

Returns :

A SeedClass, described by def.

seed_make_constructor ()

SeedObject          seed_make_constructor               (SeedContext ctx,
                                                         SeedClass klass,
                                                         SeedObjectCallAsConstructorCallback constructor);

ctx :

A SeedContext.

constructor :

The JSObjectCallAsConstructorCallback function to call when the constructor is invoked with 'new'.

Returns :

A SeedObject, which is a constructor function.