Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what do @private, @public, @class and @param mean in JS

Tags:

javascript

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;
like image 824
Bing Li Avatar asked Feb 13 '18 04:02

Bing Li


People also ask

What does @param mean in JS?

Overview. The @param tag provides the name, type, and description of a function parameter. The @param tag requires you to specify the name of the parameter you are documenting. You can also include the parameter's type, enclosed in curly brackets, and a description of the parameter.

What is private public and protected in JavaScript?

Public: These members of the class and available to everyone that can access the (owner) class instance. Private: These members are only accessible within the class that instantiated the object. Protected: This keyword allows a little more access than private members but a lot less than the public.

What does private mean in JavaScript?

A private function can only be used inside of it's parent function or module. A public function can be used inside or outside of it. Public functions can call private functions inside them, however, since they typically share the same scope.

Does JavaScript have public and private?

JS have no privacy, there is no private or public access modifier.


2 Answers

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.

like image 160
atitpatel Avatar answered Oct 22 '22 03:10

atitpatel


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.

like image 22
Paul Avatar answered Oct 22 '22 03:10

Paul