Token导航 LogoToken导航TokenDH.com
开发需要联网github未标认证来源可访问许可证需确认审计通过

method-shorthand-jsdoc方法简写 jsdoc

Agent Skill

method-shorthand-jsdoc 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

1,224

周安装

50

GitHub Stars

4,516

下载量

396
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:method-shorthand-jsdoc(方法简写 jsdoc)
来源仓库:https://github.com/epicenterhq/epicenter
仓库路径:skills/method-shorthand-jsdoc
安装命令:
npx skills add https://github.com/epicenterhq/epicenter --skill method-shorthand-jsdoc
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/epicenterhq/epicenter --skill method-shorthand-jsdoc

简介

方法

  • JSDoc 可见吗?
  • 这个
  • 有效吗?
  • 单独的助手+参考
  • 不适用
  • 返回箭头函数
  • 是的
  • 返回的方法简写
  • 是的
  • 是的
  • 方法简写是保留 JSDoc 并允许方法通过 this 相互调用的唯一方法
  • 这在工厂功能剖析中适合什么地方
  • 工厂函数遵循四区内部形状:不可变状态→可变状态→私有助手→返回对象。方法简写位于返回对象(区域 4)——公共 API 中。
  • this.method()
  • 与直接调用的决定取决于函数所在的区域:
  • 情况
  • 它住在哪里
  • 如何称呼它
  • 仅由返回对象中的同级方法使用
  • 区域 4(返回对象、方法简写)
  • this.method()
  • 由返回对象方法和预返回初始化逻辑使用
  • 第三区(私人帮手,独立功能)
  • 直接调用:helperFn()
  • 仅在初始化期间使用,不公开
  • 3区(私人帮手)
  • 直接调用:helperFn()
  • 当助手需要位于区域 3 时,其 JSDoc 对消费者不可见,但这是正确的,因为它是私有实现细节。只有第 4 区方法需要面向消费者的 JSDoc。
  • 有关完整的工厂功能剖析,请参阅闭包比关键字更好的隐私。
  • 参考文献
  • docs/articles/method-shorthand-jsdoc-preservation.md - 与文章内容相同
  • docs/articles/closures-are-better-privacy-than-keywords.md - 工厂函数剖析和区域系统
  • 每周安装量
  • 50
  • 存储库
  • 震中
  • GitHub 之星
  • 4.5K
  • 第一次看到
  • 6 天前
  • 安全审计
  • Gen Agent Trust Hub 通行证
  • 套接字通行证
  • 斯尼克通行证

SKILL.md

Method Shorthand for JSDoc Preservation

When factory functions have helper functions that are only used by returned methods, move them INTO the return object using method shorthand. This ensures JSDoc comments are properly passed through to consumers.

Related Skills: See factory-function-composition for the four-zone factory anatomy and the this decision rule.

The Problem

You write a factory function with a well-documented helper:

function createHeadDoc(options: { workspaceId: string }) {
	const { workspaceId } = options;

	/**
	 * Get the current epoch number.
	 *
	 * Computes the maximum of all client-proposed epochs.
	 * This ensures concurrent bumps converge to the same version.
	 *
	 * @returns The current epoch (0 if no bumps have occurred)
	 */
	function getEpoch(): number {
		let max = 0;
		for (const value of epochsMap.values()) {
			max = Math.max(max, value);
		}
		return max;
	}

	return {
		workspaceId,
		getEpoch, // JSDoc is NOT visible when hovering on returned object!

		bumpEpoch(): number {
			const next = getEpoch() + 1; // Calling internal helper
			return next;
		},
	};
}

When you hover over head.getEpoch() in your IDE, you see... nothing. The JSDoc is lost.

The Solution

Move the helper INTO the return object using method shorthand:

function createHeadDoc(options: { workspaceId: string }) {
	const { workspaceId } = options;

	return {
		workspaceId,

		/**
		 * Get the current epoch number.
		 *
		 * Computes the maximum of all client-proposed epochs.
		 * This ensures concurrent bumps converge to the same version.
		 *
		 * @returns The current epoch (0 if no bumps have occurred)
		 */
		getEpoch(): number {
			let max = 0;
			for (const value of epochsMap.values()) {
				max = Math.max(max, value);
			}
			return max;
		},

		bumpEpoch(): number {
			const next = this.getEpoch() + 1; // Use this.methodName()
			return next;
		},
	};
}

Now hovering over head.getEpoch() shows the full JSDoc.

Why This Works

  1. JSDoc attaches to the method definition site - when methods are inline in the return object, the JSDoc is directly on the property TypeScript sees
  2. Method shorthand uses function semantics - this is bound to the object, so this.getEpoch() works
  3. No separate helper needed - if it's only used by sibling methods, it belongs in the same object

The Pattern

// BAD: Helper defined separately, JSDoc lost on return
function createService(client) {
  /** Fetches user data with caching. */
  function fetchUser(id: string) { ... }

  return {
    fetchUser,  // JSDoc not visible to consumers!
    getProfile(id: string) {
      return fetchUser(id);  // Works, but consumers can't see docs
    },
  };
}

// GOOD: Method shorthand, JSDoc preserved
function createService(client) {
  return {
    /** Fetches user data with caching. */
    fetchUser(id: string) { ... },

    getProfile(id: string) {
      return this.fetchUser(id);  // Use this.method()
    },
  };
}

When to Apply

Use this pattern when:

  • Helper functions are ONLY used by methods in the return object
  • You want JSDoc visible when consumers hover over the method
  • The helper doesn't need to be called before the return statement

Keep helpers separate when:

  • They're called during initialization (before return)
  • They're used by multiple factories (extract to shared module)
  • They're truly internal and shouldn't be exposed

Arrow Functions Don't Work

Arrow functions don't have their own this:

// BAD: Arrow function, this is undefined
return {
  getEpoch: () => { ... },
  bumpEpoch: () => {
    this.getEpoch();  // ERROR: this is undefined!
  },
};

// GOOD: Method shorthand has correct this binding
return {
  getEpoch() { ... },
  bumpEpoch() {
    this.getEpoch();  // Works!
  },
};

Real Example

From packages/epicenter/src/core/docs/head-doc.ts:

export function createHeadDoc(options: { workspaceId: string; ydoc?: Y.Doc }) {
	const { workspaceId } = options;
	const ydoc = options.ydoc ?? new Y.Doc({ guid: workspaceId });
	const epochsMap = ydoc.getMap<number>('epochs');

	return {
		ydoc,
		workspaceId,

		/**
		 * Get the current epoch number.
		 *
		 * Computes the maximum of all client-proposed epochs.
		 * This ensures concurrent bumps converge to the same version
		 * without skipping epoch numbers.
		 *
		 * @returns The current epoch (0 if no bumps have occurred)
		 */
		getEpoch(): number {
			let max = 0;
			for (const value of epochsMap.values()) {
				max = Math.max(max, value);
			}
			return max;
		},

		/**
		 * Bump the epoch to the next version.
		 *
		 * @returns The new epoch number after bumping
		 */
		bumpEpoch(): number {
			const next = this.getEpoch() + 1;
			epochsMap.set(ydoc.clientID.toString(), next);
			return next;
		},

		// ... other methods using this.getEpoch()
	};
}

Summary

ApproachJSDoc Visible?this Works?
Separate helper + referenceNoN/A
Arrow function in returnYesNo
Method shorthand in returnYesYes

Method shorthand is the only approach that preserves JSDoc AND allows methods to call each other via this.

Where This Fits in the Factory Function Anatomy

Factory functions follow a four-zone internal shape: immutable state → mutable state → private helpers → return object. Method shorthand lives in the return object (zone 4)—the public API.

The this.method() vs direct-call decision depends on which zone the function lives in:

SituationWhere it livesHow to call it
Only used by sibling methods in the return objectZone 4 (return object, method shorthand)this.method()
Used by return-object methods AND pre-return init logicZone 3 (private helper, standalone function)Direct call: helperFn()
Used during initialization only, not exposedZone 3 (private helper)Direct call: helperFn()

When a helper needs to be in zone 3, its JSDoc won't be visible to consumers—but that's correct, because it's a private implementation detail. Only zone 4 methods need consumer-facing JSDoc.

See Closures Are Better Privacy Than Keywords for the full factory function anatomy.

References

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

38.64%
按下载量换算153

Claude

32.94%
按下载量换算130

Cursor

17.58%
按下载量换算70

Gemini CLI

8.77%
按下载量换算35

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills