我有一个AngularJS工厂,我正在尝试生成使用Jsdoc的文档。逻辑如下:
(function (angular) {
/**
* @module factories
* @memberOf angular_module
*/
var factories = angular.module('factories');
/**
* @class BaseService
* @classdesc Base object
* @param {Object} $rootScope Root scope for the application.
*/
factories.factory('BaseService', ['$rootScope', function ($rootScope) {
var baseObject = (function () {
// Prototype
var basePrototype = {
_construct: function (args) {
},
publicMethod: function (args) {
}
};
// 'Private' methods
function initialise(args) {
}
function privateMethod(param) {
}
function setObjectProperties(o, properties) {
for (prop in properties) {
if (properties.hasOwnProperty(prop)) {
o[prop] = properties[prop];
}
}
}
//-----------------------------------------------
return {
create: function (args, properties) {
function obj() { }
obj.prototype = basePrototype;
var o = new obj();
setObjectProperties(o, properties);
// Call the base object 'constructor'
o._construct(args);
return o;
}
};
})();
return {
/**
* @function create
* @memberof! BaseService
* @description Creates a new object
*/
create: function (args, properties) {
return baseObject.create(args, properties);
}
};
}
]);
/**
* @class ChildService
* @classdesc Child object
* @extends BaseService
*/
factories.factory('ChildService', ['BaseService', function (BaseService) {
return BaseService.create({ 'someProperty': true }, {
/**
* @function childPublicMethod
* @description Child public method
*/
childPublicMethod: function () {
return this.publicMethod(123);
}
});
}]);
}(angular));
在另一个文件中我有:
/**
* @namespace angular_module
*/
我遇到的问题是我想生成BaseService.create方法的文档作为BaseService文档的一部分。同样,我想为ChildService部分中的ChildService.childPublicMethod函数生成文档。但是,目前没有为BaseService.create创建任何内容,并且ChildService.childPublicMethod的文档已添加到factories模块中。我尝试过使用@lends和@alias,以及作为@memberof行的一部分的各种模块/类名组合,但到目前为止还没有给我预期的结果。感激地收到任何建议。
答案 0 :(得分:1)
我提出的解决方案如下:
(function (angular) {
/**
* @namespace factories
* @memberof angular_module
*/
var factories = angular.module('factories');
/**
* @class BaseService
* @classdesc Base object
* @param {Object} $rootScope Root scope for the application.
* @memberof angular_module.factories
*/
factories.factory('BaseService', ['$rootScope', function ($rootScope) {
var baseObject = (function () {
// Prototype
var basePrototype = {
_construct: function (config) {
},
/**
* @function publicMethod
* @description Creates a new object
* @memberof angular_module.factories.BaseService
*/
publicMethod: function (args) {
}
};
// 'Private' methods
function initialise(args) {
}
function privateMethod(param) {
}
function setObjectProperties(o, properties) {
for (prop in properties) {
if (properties.hasOwnProperty(prop)) {
o[prop] = properties[prop];
}
}
}
//-----------------------------------------------
return {
create: function (args, properties) {
function obj() { }
obj.prototype = basePrototype;
var o = new obj();
setObjectProperties(o, properties);
// Call the base object 'constructor'
o._construct(args);
return o;
}
};
})();
return {
/**
* @function create
* @description Creates a new object
* @memberof angular_module.factories.BaseService
*/
create: function (args, properties) {
return baseObject.create(args, properties);
}
};
}
]);
/**
* @class ChildService
* @classdesc Child object
* @memberof angular_module.factories
* @extends angular_module.factories.BaseService
*/
factories.factory('ChildService', ['BaseService', function (BaseService) {
return BaseService.create({ 'someProperty': true }, {
/**
* @function childPublicMethod
* @description Child public method
* @memberof ChildService
*/
childPublicMethod: function () {
return this.publicMethod(123);
}
});
}]);
}(angular));
以下是更改:
我替换了'工厂的@module声明。变量@namespace
我将@memberof angular_module.factories添加到类声明中。
我使用angular_module.factories为@extends和@memberof标记的值开始。
真的希望这可以帮助别人。