What is the proper way to document instance members that have been added through Object.defineProperties()?

I am struggling with JSDoc 3 recognizing instance properties defined using Object.defineProperties in my class. Here is a simplified version of the code I am working on:

/** @exports mymodule */
function mymodule(exports) {
    /** @constructor
      * @param {String} foo A foo.
      * @param {String} bar A bar.
      * @classdesc Has a foo and a bar.
      */
    function Example(foo, bar) {
        Object.defineProperties(this, {
            /** A foo and a bar
              * @memberof Example
              */
            foobar: { enumerable: false, value: foo + bar, writable: false }
        });
    }

    exports.Example = Example;
}

After running JSDoc, I can see output for mymodule, Example, foo, and bar, but not for foobar. Despite trying various approaches like adding @memberof mymmodule~Example and using @lends, I have not been successful in documenting foobar as part of Example.

Can anyone provide guidance on how to properly document foobar as belonging to Example?

Answer №1

Combining various examples, I finally cracked the code — using @memberof was key, but JSDoc requires modules in namepaths to be explicitly specified. Here is the successful solution I came up with:

/** Defines a foo and a bar
  *
  * @type String
  * @instance
  * @memberof module:mycustommodule~Sample
  */

Answer №2

Another approach you can consider is using the @lends annotation instead of @memberOf. Here's an example:

Object.defineProperties(this, /** @lends Sample# */{
    /** Represents a combination of foo and bar */
    foobar: { enumerable: false, value: foo + bar, writable: false }
});

Remember to include the pound symbol after the class name to indicate that the jsdoc members are instance members rather than static members.

Answer №3

It took me countless hours of experimentation, but I eventually managed to make it function using @memberOf!. Pay attention to the uppercase "O" and the exclamation mark "!"

/**
 * Explanation
 * @memberOf! MyCustomClass
 * @type {String}
 */
var myText;

Answer №4

If you prefer to utilize defineProperty instead, simply include a @type annotation (at least for IntelliJ to correctly deduce the type for the property):

/** @type AnotherType */
Object.defineProperty(this, "anotherProperty", {
    get: () => new AnotherType()
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ensure the button remains in focus after clicking on the input field: Material-Ui

I'm currently working with a material-ui dialog and I've encountered an issue. When I click on the input field, the social button loses focus which is not what I want. Here's how it looks: https://i.sstatic.net/vNRrP.png Here's the de ...

What is the best way to dynamically assign a value to an anchor tag upon each click using jQuery?

How can I pass a value to an anchor tag on every click using jQuery? I am encountering an issue with my current code where the value is not being retrieved when I click the button. //HTML snippet <button id="a-selectNm" data-a_name="<?php echo $row[ ...

Discover the ID or HREF linked to the current date using moment.js

I'm looking to dynamically add an active class to the current day in my web application. An example of how it currently works is shown below: $( document ).ready(function() { $('a[href*="2208"]').addClass('active'); }); My goal ...

Unacceptable response from AJAX function

My goal is to extract specific information from this ajax function, such as the thumbnail image and the owner of the image. It seems like the function is not recognizing data.images[i].imgurl and data.images[i].username. AJAX call in ajax.php require_o ...

Position the buttons in the react children's application

**Looking for help on positioning Black Widow in the center-left and Hulk at the bottom left of the screen. I'm having trouble figuring it out, does anyone have any tips? Also, I only want to isolate the buttons to each picture. Not sure if I need to ...

Generate a Monaco Editor within a Vue.js component

Currently, I am integrating Monaco Editor with Vue.js and facing some confusion regarding how Monaco is being instantiated within the Vue component: 1) In my data() method, I have defined an editorEx object to be used for this purpose, like so: data() { ...

Slide in the Toggle Effect to Your Navigation Menu

Seeking help with enhancing my jQuery dropdown menu to include a slide down toggle effect similar to this example: http://jsfiddle.net/LaSsr/188/. Any assistance in applying this slide effect to the following JSfiddle would be greatly appreciated. Thank yo ...

What is the best way to keep my data within a global variable?

$(function(){ let spaceTravelersData; $.getJSON('http://api.open-notify.org/astros.json', retrieveData); function retrieveData(data) { spaceTravelersData = data; } alert(spaceTravelersData.people[0].name) }); I a ...

Solving routing issues using object constructors in expressjs

Currently, I am in the early stages of developing an API REST using express and nodejs. As part of my routing process, I have decided to create separate "controllers" for each route and call these controllers within a router file. For example: ... router. ...

Error message: The protocol "https:" is not compatible with this function. Please use "http:" instead

I decided to use IBM Bluemix for my school project, where I am working on creating a web service. For my project, I need to fetch JSON data from an API in order to utilize the provided information. Currently, I am utilizing the http get method to retrieve ...

Is there a way to change the URL in the address bar without refreshing the page?

Is it possible to update the URL in the address bar without reloading the page? I came across 2 potential solutions: Option 1: Check out this link It involves using window.history.replaceState. But when I tried implementing it in my angularjs projec ...

Add a JavaScript file into a PHP document

I've been searching for a solution in various forums, but the main answer I found doesn't seem to work for me. As someone new to Web development, I'm attempting to create a simple JavaScript program that takes a JSON string of products and ...

What are the steps to integrate node-inspector with `npm start` in my application?

Currently, I am utilizing npm start to kickstart my MEAN stack application. However, I am interested in using the node-inspector to debug some Mongoose aspects. I am aware that the node inspector can be initiated with node-inspector, but I am unsure of wha ...

Binding an event to an Angular 2 component directly within its selector code

Looking at my Angular 2 component: import { Component, ElementRef, Renderer } from '@angular/core';; @Component({ selector: 'my-button', templateUrl: 'button.html' }) export class ButtonComponent { private text: string ...

JavaScript and CSS animations offer dynamic and engaging ways to bring

I'm working on a div section and I want it to come down and rotate when a button is clicked. However, after moving to the bottom, it doesn't rotate as expected but instead returns to its initial position along the Y axis. How can I fix this issue ...

Accessing data from localhost using Vue.js and Axios is restricted due to CORS policy and the error "Access to XMLHttpRequest" may be

Having a minor issue... Trying to retrieve a basic json file from my server for testing purposes (not an actual API). Utilizing VueJS and axios. Here is my code : getServicesAPI() { axios.get("http://51.91..../dist/API/Services.json").the ...

I made a mistake with my git repository. Should I try to fix it or just start fresh?

After spending months learning web development, I recently completed my first project. Unfortunately, right before deployment, I made a mistake with my backend git tree. I attempted to resolve the issue using suggestions from other resources, but none of ...

How can you display an alert message when new data is successfully added to a database using ajax?

In my web application, I have implemented a functionality to display an alert message when new data is successfully inserted into the database. The Ajax code below is responsible for sending a request to the EditDeleteLecture.php file. However, a challenge ...

Having trouble processing a JSON object using Jquery?

Hello, I am currently working on parsing a JSON object using jQuery. So far, I have successfully extracted all the necessary information from the results except for one crucial piece - the performance tags. Each JSON result is enclosed in an event tag and ...

Is Angular File API Support Compatible with HTML5?

When checking for HTML5 File API browser support in my code: private hasHtml5FileApiSupport; constructor(@Optional() @Inject(DOCUMENT) document: Document) { const w = document.defaultView; this.hasHtml5FileApiSupport = w.File && w.FileReader & ...