文档例如 JSDoc 中的静态方法名称路径

kav*_*vun 5 javascript documentation jsdoc

在记录 javascript 方法时,我知道#在名称路径中使用表示实例方法,例如:

function Class() {}

/**
 * Class#method1
 */
Class.prototype.method1 = function () {}
Run Code Online (Sandbox Code Playgroud)

但是,我也看到了~和 的用法.。那些是干什么用的?

/**
 * Class~method2
 * Class.method3
 */
Run Code Online (Sandbox Code Playgroud)

还有其他我应该注意的语法吗?

rob*_*rit 5

您可以在此处查看变量/方法命名约定的详细信息。

.用于表示一个类的方法(也称为一个静态方法),而不是一个实例方法。这意味着在类的实例(用 创造的东西new)上你不能调用类方法。

例子:

Class.foo = function () {
  // ...
};

var blah = new Class();
blah.foo();  // throws an error

Class.foo();  // actually calls the function
Run Code Online (Sandbox Code Playgroud)

~用于表示一个内方法(也被称为私有方法),这是使用的类的一个方法中限定的一个function。这些类型的方法通常无法从方法外部访问,因此您很少会看到这些方法的文档。

例子:

function Class() {
  // this function is not accessible outside of the constructor
  function inner() {
  }

  // unless we give it some other reference that is visible:
  this.accessInner = inner;
}

blah = new Class();
blah.inner();        // throws an error
Class.inner();       // also throws an error
blah.accessInner();  // will actually call inner
Run Code Online (Sandbox Code Playgroud)