使用自定义继承系统记录复杂的JavaScript对象 [英] Documenting complex JavaScript Objects with custom Inheritance System
问题描述
我正在尝试将现有的服务器端JavaScript API从其现有的手动复制和粘贴继承系统迁移到更好更可靠的系统。纯原型不能使用,因为对象的状态(变量)也必须被继承,并且不能在父对象中覆盖。
I'm currently trying to migrate an existing server-side JavaScript API from its existing manually copy-and paste Inheritance System to a better and more reliable system. The pure prototyping cannot be used because state (variables) of the objects must also be inherited and must not be overriden in parent Objects.
所以我正在考虑使用来自John Reisig的好解决方案在这里描述:
http://ejohn.org/blog/ simple-javascript-inheritance /
So i'm thinking about using a good solution from John Reisig described here: http://ejohn.org/blog/simple-javascript-inheritance/
这个工作对我来说非常棒。
which workrs great for my case.
唯一的挑战我现在面临的是,大多数文档框架不会处理像这样的对象(或者我只是不知道如何告诉他们)。所以我的问题是,我如何记录这样的类:
The only challenge i'm facing now is that most of the documentation frameworks won't handle objects constructed like this (OR i just don't know how to tell them). So my question is, how can i document classes like this:
namespace.ClassA = Class.extend({
name : "",
init: function(name){
this.name = name;
}
});
namespace.ClassB = ClassA.extend({
sayName : function(){
console.log(this.name);
}
});
我更喜欢JsDoc,但我无法想到一种记录这种类的类的方式JsDoc。我也尝试了NaturalDocs,这将是一种工作,但我并不希望所有这些额外的python的东西在构建过程。
I'm preferring JsDoc but i couldn't think of a way to document this kind of classes with JsDoc. I also tried NaturalDocs which would kind-of work but i don't really want all this extra python stuff to be in the build process.
我认为主要的问题我有命名空间
I think the main problems i have are with namespaces
例如:
/** @memberof namespace**/
namespace.ClassB = ClassA.extend(
/** @lends ClassB.prototype **/
{
/** @constructs **/
init : function(){
},
sayName : function(){
console.log(this.name);
}
});
不会在命名空间namespace中包含或显示ClassB
will not include or display ClassB within the namespace "namespace"
推荐答案
查看以下内容是否适合您。请注意,您的代码片段本身不是有效的JavaScript,因为命名空间
在任何地方都未定义。无论如何,jsdoc将会处理它。我不得不做的是比我以前会更加冗长。一些注释:
See if the following works for you. Note that your code snippet is not valid JavaScript in and of itself because namespace
is not defined anywhere. At any rate, jsdoc will process it. What I've had to do was to be more verbose than I would have otherwise been. A few notes:
-
您可以将定义
ClassA
在namespace.ClassA
的行前面。
@借用
标签需要一个完整路径: / ** @lends namespace.ClassB.prototype * /
The @lends
tag needs a full path: /** @lends namespace.ClassB.prototype */
这是代码:
/**
* @namespace namespace
*/
namespace.ClassA = Class.extend({
name : "",
/**
* @constructor
* @memberof namespace
* @name ClassA
* @param name Blah.
*/
init: function(name){
this.name = name;
}
});
/**
* @constructor
* @memberof namespace
* @name ClassB
*/
namespace.ClassB = ClassA.extend(/** @lends namespace.ClassB.prototype */ {
/**
* @method
*/
sayName : function(){
console.log(this.name);
}
});
这篇关于使用自定义继承系统记录复杂的JavaScript对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!