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

154
Views
Inquiry to write function to javascript Object JSDoc property

I need to put a function in a javascript object, how do I add a JSDoc comment in this case?

/**
 * @typedef {Object} testObj
 * @property {!String} testName - testName
 * @property {?Function} [testFunction=null] - testFunction
 *
 */
var testObj = {
    testName:null,
    testFunction:null
}

In this form, null is the default value for the function, so it is expressed like this.

I just want to ask if it is enough to write only the @property {?Function} and write the parameter in the Object part, or if there is another way.

In the testFunction above, I want to show in JSDoc that a function with parameters {Number} a, {number} b, {Object} c is put in. If there is a way, I would appreciate it if you let me know. And I also want to express that this function returns a String.

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

0

Use @function to define the function first, and then use the name of the function anywhere you need it, example:

/**
 * A test function
 *
 * @function testFunction
 * @param  {number} a Number a
 * @param  {number} b Number b
 * @param  {Object} c Object c
 * @returns {string} Returns a string
 */

/**
 * A test Object
 *
 * @typedef {Object} testObj
 * @property {!string} testName The Test Name
 * @property {?testFunction} testFunction The Test Function
 */
const testObj = {
  testName: null,
  testFunction: null,
}

Just tested it with jsdoc and the documentation is generated correctly with the link in the testFunction property.

enter image description here

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!