使用JSDOC记录范围

时间:2014-03-11 09:51:53

标签: javascript jquery jsdoc

我很难用JSDOC来记录范围,任何人都可以告诉我们记录以下代码的正确方法:

(现在,jsdoc生成GLOBAL函数中的所有方法,它们应该属于WorkAreaPlugin)

/**
 * @namespaces Retalix.StoreOfficeClient.Web.Scripts.General.WorkArea
 * @scope WorkAreaPlugin
 */
(function ($, undefined) {

/**
 * Description
 * @constructor
 * @method ctor
 * @param {} options     
 * @return 
 */
var ctor = function (options) {
    var self = this;
    var _data;
    var _new;
    var _grids = {};

    if (this.setupAjaxCrud) {
        this.setupAjaxCrud();
    }

    $.extend(self,
        {
        /**
         * Sets the data property of the current scope and setups the set_isDirty and the get_isDirty functions if not exist to the data object 
         * @method set_data
         * @param {} data
         * @param {} triggerChange
         * @return 
         */
        set_data: function (data, triggerChange) {
            _data = data || {};
            if (!_data.set_isDirty) {
                $.setupDirtyFunctions(_data);
            }
            if (triggerChange !== false) {
                self.trigger("dataChanged", [_data, self]);
            }
        }
    });

    this.bind("login", function () {
        var isDirty = self.isDirty();
        if (!isDirty && self.loader && $.isFunction(self.loader.doLoading)) {
            self.reload();
        }
    });
};

StoreOfficeClient.Plugins.Register("workArea", undefined, undefined, ctor);

})(jQuery);

1 个答案:

答案 0 :(得分:1)

让我先言指出,使用jsdoc记录JavaScript代码通常归结为一个约定问题,以及如何将JS实体之间的关系呈现给阅读文档的人。所以以下是一个可能的答案。

以下内容将所有内容放在一个命名空间中:

/**
 * @namespace Retalix.StoreOfficeClient.Web.Scripts.General.WorkArea.WorkAreaPlugin
 *
 */
(/** @lends Retalix.StoreOfficeClient.Web.Scripts.General.WorkArea.WorkAreaPlugin */ function ($, undefined) {

/**
 * Description
 * @constructor
 * @param {} options
 */
var ctor = function (options) {
    var self = this;
    var _data;
    var _new;
    var _grids = {};

    if (this.setupAjaxCrud) {
        this.setupAjaxCrud();
    }

    $.extend(self,
             /** @lends Retalix.StoreOfficeClient.Web.Scripts.General.WorkArea.WorkAreaPlugin~ctor# */ {
        /**
         * Sets the data property of the current scope and setups the set_isDirty and the get_isDirty functions if not exist to the data object
         * @param {} data
         * @param {} triggerChange
         */
        set_data: function (data, triggerChange) {
            _data = data || {};
            if (!_data.set_isDirty) {
                $.setupDirtyFunctions(_data);
            }
            if (triggerChange !== false) {
                self.trigger("dataChanged", [_data, self]);
            }
        }
    });

    this.bind("login", function () {
        var isDirty = self.isDirty();
        if (!isDirty && self.loader && $.isFunction(self.loader.doLoading)) {
            self.reload();
        }
    });
};

StoreOfficeClient.Plugins.Register("workArea", undefined, undefined, ctor);

})(jQuery);