文档中 Javascript 对象的类定义

发布于 2024-12-22 01:23:06 字数 910 浏览 1 评论 0原文

我正在开发一个 javascript 库,由一个主对象组成,它作为静态类工作,并包含执行相同操作的各种对象。
我无法找到引用文档中对象的最佳方法,因为我正在使用 jGrouse 并将它们称为类,例如:

public Class myLibrary

这些对象及其子对象都不会有任何原始类型变量,也不会有任何工厂因此,它们不会被重新实例化。

我无法向您展示一个实例,但我会尝试在这里放一个类似的示例:

var myLibrary = {};
myLibrary.methodOne = function(){ ... };
myLibrary.methodTwo = function(){ ... };

// this is a sub-library that will encapsulate methods for Array type operations
 myLibrary.Array = {};
 myLibrary.Array.forEach = function(array, function(item));
 (...)

// this is a sub-library that will encapsulate methods for Event type operations
myLibrary.Events = {};
(...)

因此,出于显而易见的原因,我认为将 myLibrary、myLibrary.Array 和 myLibrary.Events 作为类引用是不正确的它们不应该被实例化。
我拒绝将它们称为静态类,因为 Javascript 本身并不是设计用于处理静态类的。
我认为对象和内部对象或静态对象可能也不是正确的选择。

我正在寻找在我的公共文档中识别它们的最佳方法,以免混淆没有经验的程序员,也不会侮辱更高级的开发人员。

有什么帮助吗? 谢谢

I'm developing a javascript library, composed by a main object, that works as a static Class and contains various objects that do the same thing.
I am having trouble finding the best way to refer to the objects in the documentation, as i am using jGrouse and it refers to them as Classes, like:

public Class myLibrary

None of these objects and it's children will have any primitive type variables nor will have any factory pattern associated so, they are not to be reinstantiated.

I can't show you a live example, but i'll try to put here an analogous one:

var myLibrary = {};
myLibrary.methodOne = function(){ ... };
myLibrary.methodTwo = function(){ ... };

// this is a sub-library that will encapsulate methods for Array type operations
 myLibrary.Array = {};
 myLibrary.Array.forEach = function(array, function(item));
 (...)

// this is a sub-library that will encapsulate methods for Event type operations
myLibrary.Events = {};
(...)

So, i don't think it's correct to refer to myLibrary, myLibrary.Array and myLibrary.Events as Classes, for the obvious reason that they are not meant to be instantiated.
I reject the idea to call them Static Classes as Javascript isn't design to work with static classes per se.
I think Object and Inner Object or Static Object may not be the way to go also.

I'm looking for the best way to identify them in my public documentation, as for not to confuse unexperienced programmers nor insult the more advanced developers.

Any help?
thanx

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

删除会话 2024-12-29 01:23:06

您可能正在寻找术语“命名空间”。

你真的不应该太担心这个词的正确性。它们都太模糊了,并且在 JavaScript 亚文化中具有完全不同的含义。

文档中要说的重要一点是“事件有这些方法”。

我想查看方法签名,我想查看它们所做的事情的高级描述,我想查看一个示例。

Your probably looking for the term "namespace".

You really shouldn't worry so much about the correct word. The are all far too vague and have completely separate meaning is several different meanings in JavaScript sub cultures.

The important thing to say in documentation is that "The Event has these methods".

I want to see the method signatures, I want to see a high level description of what they do and I want to see an example.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文