Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

270
Views
How to document that a constructor function generates objects which have what properties (and also methods)?

I have a constructor function, and Im using JSDoc to document it:

/**
 * @constructor
 * @param {String} title The title of the task
 * @param {Boolean} important Whether the task is important of not
 */
function Task(title, important) {
    this.title = title
    this.important = important

    // 1 presents to 'unfinished', 2 presents to 'processing', 3 presents to 'finished'
    this.state = 1
}

The documentation is generated:

enter image description here

But here is a thing. You see in my constructor function, it is has a property with the name of state, and there is no paramater use to set the value of the state property.

And so when I document this Task constructor function, I have no idea how to tell the readers this function generates objects which have a state property. And by the way, I think the developers when they read the documentation, they will know the objects generated by this Task function has the title and important properties is because those properties documented under parameters. And since the state property it doesn't "rely" on any parameter, I don't know how to show it on the documentation.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Add a @typedef type definition for your Task objects:

/**
 * @typedef {object} Task
 * @property {string} title The title of the task
 * @property {boolean} important Whether the task is important of not
 * @property {number} state 1 represents 'unfinished', 2 represents 'processing', 3 represents 'finished'
 */

and add a @returns to your constructor function documentation:

/**
 * @constructor
 * @param {String} title The title of the task
 * @param {Boolean} important Whether the task is important of not
 * @returns {Task} a task object
 */
function Task(title, important) {
    this.title = title
    this.important = important

    // 1 presents to 'unfinished', 2 presents to 'processing', 3 presents to 'finished'
    this.state = 1
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!