首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在angular中记录由工厂函数使用ngdoc创建的对象?

如何在angular中记录由工厂函数使用ngdoc创建的对象?
EN

Stack Overflow用户
提问于 2016-08-12 20:09:39
回答 1查看 239关注 0票数 2

我如何使用ngdoc来记录一个返回了一个‘工厂函数’的'angular factory‘?具体地说,我如何记录我的“工厂函数”创建的对象?

在下面的设计示例中,我已经记录了如何使用工厂来创建页面对象,但是如何记录如何使用页面对象本身呢?

代码语言:javascript
复制
angular.module('fooRestClient').factory('page', function () {

   var prototype = {};

  // Below I need to somehow link the methods a page object has to the
  // factory's documentation.

  /**
   * @description Fetches the page at the specified index.
   *
   * @param {number} index - the index of the page to fetch
   *
   * @returns {object} a page object representing the page at the given index
   */
   prototype.getPage = function (index) {
      // returns a new page.
   };

   // ... more useful methods.

   /**
    * @ngdoc service
    * @type function
    * @name fooRestClient:page
    * @description
    * A factory function for producing page objects....  
    *
    * @param {Number} index - The page index.
    * @param {Number} size - The page size.
    * @param {Number} total - The total number of pages.
    * @param {Array}  data - The contents of the page.
    * @returns {object} A page object for the given resource
    */
    return function page(index, size, total, data) {
        return Object.create(prototype, {
            index: index,
            size: size,
            total: total,
            data: data
        });
    };

});

我在SO上找到的最接近的匹配项是:How to document a factory that returns a class in angular with ngdoc?。这没有什么帮助,因为我没有一个"class“名称来链接这些方法,因为我没有使用伪经典继承。

EN

回答 1

Stack Overflow用户

发布于 2016-11-06 22:24:58

也许这就是你所期望的:

代码语言:javascript
复制
    /**
     * @ngdoc service
     * @type function
     * @name fooRestClient:page
     * @description
     * A factory function for producing page objects....
     *
     * @param {Number} index - The page index.
     * @param {Number} size - The page size.
     * @param {Number} total - The total number of pages.
     * @param {Array}  data - The contents of the page.
     * @returns {object} A {@link prototypeInstance|page object} for the given resource
     */

    return function page(index, size, total, data) {
      /**
       * @ngdoc object
       * @name prototypeInstance
       * @description page object for the given resource
       */
      return Object.create(prototype, {
        /*
         * @ngdoc object
         * @name prototypeInstance#index
         * @description index description
         */
        index: index,
        /*
         * @ngdoc object
         * @name prototypeInstance#size
         * @description size description
         */
        size: size,
        /*
         * @ngdoc object
         * @name prototypeInstance#total
         * @description total description
         */
        total: total,
        /*
         * @ngdoc object
         * @name prototypeInstance#data
         * @description data description
         */
        data: data
      });
    };

我知道这有点冗长,但这是我做这类事情的唯一方法

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38917635

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档