Class construction and inheritance

This material is the part that survived in tp from the old way Tripous created JavaScript classes, before the class keyword became part of the language. Modern JavaScript has native class syntax now, but these helpers are still present because some Tripous code still uses or explains that earlier pattern.

Modern Tripous JavaScript uses normal JavaScript classes and extends wherever possible. Tripous also has a small set of helpers for function-constructor inheritance: tp.SetBaseClass(), tp.Property(), tp.Constant(), and tp.CreateInstance().

These helpers are still useful when reading function-constructor code or when a small constructor function is simpler than a class. This demo shows both styles side by side. The important rule is that class extends is the normal style for new code, while tp.SetBaseClass() is kept mainly for old function-constructor patterns.

Modern class inheritance

A derived class uses JavaScript extends, calls super(), and can be created directly or through tp.CreateInstance().

Legacy function constructors

tp.SetBaseClass(Derived, Base) wires the prototype chain for old function-constructor code and returns the base prototype.

Property helper

tp.Property() defines a property on a prototype or object. It can create either a plain value property or a getter/setter property.

Constant helper

tp.Constant() defines a non-writable, non-enumerable property. It is useful for metadata-style values that should not be changed by normal code.