JavaScript 領域

在版本 1.0 中新增。

JavaScript 領域 (名稱 js) 提供以下指令

.. js:module:: name

此指令設定後續物件宣告的模組名稱。模組名稱用於全域模組索引和交叉參考中。此指令不會像 py:class 指令那樣建立物件標題,例如。

預設情況下,此指令將建立可連結的實體,並在全域模組索引中建立一個條目,除非指定了 no-index 選項。如果指定了此選項,則該指令僅更新當前模組名稱。

在版本 1.6 中新增。

在版本 5.2 中變更:模組指令支援主體內容。

.. js:function:: name(signature)

描述 JavaScript 函數或方法。 如果您想將參數描述為可選,請使用方括號,如 Python 簽名的文件中所述。

您可以使用欄位來提供有關參數及其預期類型、函數可能拋出的錯誤以及傳回值的更多詳細資訊

.. js:function:: $.getJSON(href, callback[, errback])

   :param string href: An URI to the location of the resource.
   :param callback: Gets called with the object.
   :param errback:
       Gets called in case the request fails. And a lot of other
       text so we need multiple lines.
   :throws SomeError: For whatever reason in that case.
   :returns: Something.

這會呈現為

$.getJSON(href, callback[, errback])
參數:
  • href (string()) – 資源位置的 URI。

  • callback – 使用物件呼叫。

  • errback – 在請求失敗時呼叫。 以及很多其他文字,所以我們需要多行。

拋出:

SomeError() – 在該情況下的任何原因。

傳回:

某物。

:single-line-parameter-list: (no value)

確保函數的參數將在單個邏輯行上發出,覆蓋 javascript_maximum_signature_line_lengthmaximum_signature_line_length

在版本 7.1 中新增。

.. js:method:: name(signature)

此指令是 js:function 的別名,但它描述的是在類別物件上作為方法實作的函數。

在版本 1.6 中新增。

:single-line-parameter-list: (no value)

確保函數的參數將在單個邏輯行上發出,覆蓋 javascript_maximum_signature_line_lengthmaximum_signature_line_length

在版本 7.1 中新增。

.. js:class:: name

描述建立物件的建構子。 這基本上像一個函數,但會顯示 class 前綴

.. js:class:: MyAnimal(name[, age])

   :param string name: The name of the animal
   :param number age: an optional age for the animal

這會呈現為

class MyAnimal(name[, age])
參數:
  • name (string()) – 動物的名稱

  • age (number()) – 動物的可選年齡

:single-line-parameter-list: (no value)

確保函數的參數將在單個邏輯行上發出,覆蓋 javascript_maximum_signature_line_lengthmaximum_signature_line_length

在版本 7.1 中新增。

.. js:data:: name

描述全域變數或常數。

.. js:attribute:: object.name

描述 object 的屬性 name

提供這些角色來參考描述的物件

:js:mod:
:js:func:
:js:meth:
:js:class:
:js:data:
:js:attr: