最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - what do @private, @public, @class and @param mean in JS - Stack Overflow

programmeradmin6浏览0评论

Hello to whoever can help

Please refer to the code below. I just want to understand what do @private, @public, @class, and @param mean in JavaScript. Do they do anything in JavaScript or they are just there as indications to tell programmer they are what they are?

/**
 * 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;

Hello to whoever can help

Please refer to the code below. I just want to understand what do @private, @public, @class, and @param mean in JavaScript. Do they do anything in JavaScript or they are just there as indications to tell programmer they are what they are?

/**
 * 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;
Share Improve this question edited Feb 13, 2018 at 4:32 Bing Li asked Feb 13, 2018 at 4:30 Bing LiBing Li 5091 gold badge6 silver badges11 bronze badges 2
  • 8 They’re JSDoc annotations. No actual effect. – Ry- Commented Feb 13, 2018 at 4:33
  • 1 Refer this. github.com/google/closure-compiler/wiki/… – syam Commented Feb 13, 2018 at 4:34
Add a comment  | 

2 Answers 2

Reset to default 37

These are known as Tags in Javascript. They are used for documentation. You have rightly guessed that they help programmers to understand the code better. Let us take one by one from the above example.

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.

Hope this helps. You can read more about tags here under Block Tags.

Those are in comments, the JS interpreter won’t even read them. They are comments for the developer and possibly can be used by an auto documentation tool or IDE for syntax help.

发布评论

评论列表(0)

  1. 暂无评论