Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8909885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:32:52+00:00 2026-06-15T03:32:52+00:00

I’m using JsDoc3 and the Closure Compiler . I use a JsDoc template which

  • 0

I’m using JsDoc3 and the Closure Compiler. I use a JsDoc template which outputs JSON for me to make HTML from it with a custom script.

I have a function which returns a custom class (but I don’t have, nor need, a constructor), and I want to be able to document it (the function), and the functions present in the returned object.

myLib.defer = function() {

    return {
        'then':    function() {},
        'resolve': function() {},
        'reject':  function() {},
        'notify':  function() {},
        'promise': function() {}
    };

};

How do I document this? I don’t have a constructor, nor I need one. I do not care that much about documenting the “class” (I don’t need one, and besides, the object returned is documented in the @return of this function), the only thing I need is to document the functions that are present in the returned object, so they end up in the JsDoc’s JSON output for me to grab.

Also, I’m using Closure Compiler’s AVANCED_OPTIMIZATIONS mode, so if any workaround’s side effects (such as useless code) will be supressed by that, it’s a good workaround.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:32:54+00:00Added an answer on June 15, 2026 at 3:32 am

    Unfortunately there is no way to do this that doesn’t look awkward, but this works.

    Firstly, one can document a class that doesn’t have a constructor with an interface, as Chad mentioned. It looks like this:

    /**
     * Description of the Deferred interface.
     * @interface Deferred
     */
    function Deferred() {}
    

    And one can document methods of it like this (for example):

    /**
     * Returns a Promise
     * @function Deferred.promise
     * @return {Promise} A Promise.
     */
    Deferred.prototype.promise = function() {};
    

    Then, on the function that returns your constructor-less class, you annotate your return like this:

    myLib.defer = function() {
    
        /** @type {Deferred} */
        return {
            'then':    function() {},
            'resolve': function() {},
            'reject':  function() {},
            'notify':  function() {},
            'promise': function() {}
        };
    
    };
    

    However, this will only pass Closure Compiler; it won’t get rightly converted by the JsDoc3 JSON export template (maybe the regular one too), so we need this @class annotation (which CC ignores):

    /**
     * Description of the Deferred interface.
     * @interface Deferred
     * @class Deferred
     */
    function Deferred() {}
    

    With all of this in place, our docs will be generated correctly, and our code will compile to the same it did before – all the boilerplate is removed as dead code upon compilation.

    Update: As Chad mentions, you wouldn’t get a warning if you tried to instantiate a non-interface directly, which can be bad, and you may not like that (Interfaces will throw an error if instantiated).

    One way to go about this is making the interface constructor @private to a @const object literal, as mentioned in his answer to that question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a text area in my form which accepts all possible characters from
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have thousands of HTML files to process using Groovy/Java and I need to
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.