Hoc classes ctor

From openreachtech/hora-skills-ort-core · View interactive version

Hoc classes ctor is an AI agent skill from the GitHub repository openreachtech/hora-skills-ort-core. The `Ctor` getter an instance reaches its own class through: how `#get:Ctor` is defined, typed and overridden, why the name is reserved, and why a static member is never reached through `this.constructor` outside it. Use when an instance member refers to a static member or to its own class, or when

How to use this skill

Skill file

Classes: Ctor

How an instance reaches its own class. Ctor is the library's word for a class held as a value,

and #get:Ctor is the one getter that hands an instance its own.

An instance reaches its class through `#get:Ctor`

Neither the class name nor this.constructor is written there: for a static member,

this.constructor appears in one place only, the body of #get:Ctor.

the instance's own constructor is what lets a call from an inheriting subclass reach the

subclass's own static definition.

checker to know which static members exist. #get:Ctor is where that type is settled, once.

this.constructor: cast it to the type of the class in question.

constructor that needs no type resolution — this.constructor.name above all — is read

directly, as the class name in an error message is:

` throw new Error(${this.constructor.name}#normalizeValue() must be inherited) `.

/**
 * get: Constructor of this class.
 *
 * @returns {typeof SampleClass} Constructor of this class.
 */
get Ctor () {
  return /** @type {typeof SampleClass} */ (this.constructor)
}

someInstanceMethod () {
  return this.Ctor.someStaticMethod()
}

// NG: this.constructor written outside #get:Ctor
someInstanceMethod () {
  return this.constructor.someStaticMethod()
}

When a derived class has more static members to reference, override `#get:Ctor`

class DerivedSample extends BaseSample {
  /** @override */
  get Ctor () {
    return /** @type {typeof DerivedSample} */ (this.constructor)
  }

  someDerivedMethod () {
    return this.Ctor.derivedStaticMethod()
  }
}

Do not define a `#get:xxxx` shortcut for `this.Ctor.xxxx`

// NG: a shortcut getter for this.Ctor.DEFAULT_VALUE (makes the static reference implicit)
get defaultValue () {
  return this.Ctor.DEFAULT_VALUE
}

// OK: reference static members explicitly via this.Ctor
someInstanceMethod () {
  return this.Ctor.DEFAULT_VALUE
}

The name `Ctor` is reserved

nothing else.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.