hoc-classes-ctor
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…
от openreachtech★ 17 звёзд на GitHub
Установить hoc-classes-ctor в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
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
- When an instance method or getter refers to a static member, it goes through
this.Ctor. Neither the class name northis.constructoris written there: for a static member,this.constructorappears in one place only, the body of#get:Ctor. - Hardcoding the class name fixes the reference to the base class's definition. Going through the instance's own constructor is what lets a call from an inheriting subclass reach the subclass's own static definition.
this.constructorwritten directly reaches the same class, but its type is too broad for the checker to know which static members exist.#get:Ctoris where that type is settled, once.- In the body of
#get:Ctor, type resolution (a type cast) is needed betweenreturnandthis.constructor: cast it to the type of the class in question. #get:Ctoris an adapter that exists to resolve the type. A native property of the constructor that needs no type resolution —this.constructor.nameabove 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
- When a derived class gains additional "static members referenced from instance members," override and redefine
#get:Ctorin the derived class, resolving the type to the derived class's type.
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
- Do not define a getter (
#get:xxxx) solely to accessthis.Ctor.xxxx(a static member). Write static member access explicitly asthis.Ctor.xxxx. - Reason: inserting such a getter makes it implicit, from the caller's
this.xxxx, that this is a static-member call.
// 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
#get:Ctoris reserved as the conventional getter that returnsthis.constructor.- Therefore, do not use the name
Ctoras a member name for any other purpose. Ctoris a getter, so the accessors convention holds for it in full: its body is the cast and nothing else.
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл hoc-classes-ctor?
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 about to write `this.constructor`. Getters that hold a dependency's class belong to the dependency-wiring convention.
Как установить скилл hoc-classes-ctor?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл hoc-classes-ctor запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
AnthropicGuide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
academy-guide
AnthropicStop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
internal-comms
AnthropicA set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
skill-development
AnthropicThis skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…