gpt4 book ai didi

javascript - @private、@public、@class 和 @param 在 JS 中是什么意思

转载 作者:行者123 更新时间:2023-12-01 15:50:48 25 4
gpt4 key购买 nike

你好谁可以帮助

请引用下面的代码。我只是想了解 @private、@public、@class 和 @param 在 JavaScript 中的含义。它们是否在 JavaScript 中做了任何事情,或者它们只是作为告诉程序员它们是什么的迹象?

/**
* Event functions references.
* @private
*/
e = {
_onDragStart: null,
_onDragMove: null,
_onDragEnd: null,
_transitionEnd: null,
_resizer: null,
_responsiveCall: null,
_goToLoop: null,
_checkVisibile: null
};

/**
* Creates a carousel.
* @class The Owl Carousel.
* @public
* @param {HTMLElement|jQuery} element - The element to create the carousel for.
* @param {Object} [options] - The options
*/
function Owl(element, options) {

/**
* Current settings for the carousel.
* @public
*/
this.settings = null;

最佳答案

这些在 Javascript 中被称为标签。它们用于文档。您猜对了,它们可以帮助程序员更好地理解代码。让我们从上面的例子中一一列举。
The @private tag marks a symbol as private, or not meant for general use.

So, variable e is supposed to be private and shouldn't be accessed outside the current class.


The @class tag marks a function as being a constructor, meant to be called with the new keyword to return an instance.

So here it says that function Owl is a constructor function and should be called with a new keyword while being invoked.


The @public opposed to @private suggests that the function is publicly available to be accessed outside the current context.

Hence, owl function can be called outside the current class.


The @param describe the parameters of the function. There are three parts of it. First is within {}. It suggests the type of the param. Second is name of the param. Third is after they hyphen(-) sign. It describes the parameter.

So, we have two parameters here. First is of HTMLElement or jQuery type, named element which has description : The element to create the carousel for. Second is of Object type named options with description : The options.



希望这可以帮助。您可以阅读有关标签的更多信息 here在 block 标签下。

关于javascript - @private、@public、@class 和 @param 在 JS 中是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48759485/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com