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

  • SEARCH
  • Home
  • 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 4265742
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:39:57+00:00 2026-05-21T06:39:57+00:00

I have a JavaScript singleton object created with closure method: /** * This is

  • 0

I have a JavaScript singleton object created with closure method:

/**
 * This is the singleton.
 *
 * @namespace window.Something.Singleton
 */
window.Something.Singleton = (function() {
  /**
   * Foo method.
   *
   * @return {String} this method always returns with <code>bar</code>
   */
  function _foo() { return "bar"; }

  /**
   * @lends window.Something.Singleton#
   */
  return {
    /**
     * @borrows window.Something-_foo
     * @function
     */
    foo: _foo
  };
}());

But the jsdoc-toolkit does not generate the inherited documentation from _foo method to the foo method what I would like to have.

If I write @see instead of @borrows it works (inserts a link to the correct method), but I don’t want to copy&paste the documentation for the foo method to have a public documentation as well.

  • 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-05-21T06:39:57+00:00Added an answer on May 21, 2026 at 6:39 am

    I did some tests, and I have good news and bad news :). The good news is that it looks like you can get this to work by putting the @borrows tag in the Singleton doc comment:

    /**
     * This is the singleton.
     *
     * @namespace Something.Singleton
     * @borrows Something.Singleton-_foo as foo
     */
    Something.Singleton = (function() {
       // etc
    })());
    

    But this has several ramifications, good and bad:

    • The foo function is marked static. This is probably a good thing, as it seems to be accurate as I understand your code.
    • With the code as it is currently shown (i.e. no more methods on the singleton, etc), you can dispense with the @lends tag entirely, unless you want to include it for clarity. If all methods are listed as @borrows on the top singleton namespace, then you don’t need to further document them in the returned object. Again, this is probably a good thing.
    • The bad news is that I couldn’t get this to work unless the borrowed method was explicitly marked @public – which makes it show up, redundantly, in the documentation. I think this is unavoidable – if jsdoc-toolkit thinks the method is private, it won’t create documentation, so you can’t refer to it (I get WARNING: Can't borrow undocumented Something.Singleton-_foo.). If the method is public, it gets displayed in the documentation.

    So this works:

    /**
     * This is the singleton.
     *
     * @namespace Something.Singleton
     * @borrows Something.Singleton-_foo as foo
     */
    Something.Singleton = (function() {
      /**
       * @public
       * Foo method.
       *
       * @return {String} this method always returns with <code>bar</code>
       */
      function _foo() { return "bar"; }
    
      return {
        foo: _foo
      };
    }());
    

    …in that it copies the documentation for _foo to foo, but it will display _foo in the documentation page as well:

    Method Summary
    <inner>  _foo()
    <static>  Something.Singleton.foo()
    

    Probably the best workaround is simply to forget @borrows entirely and explicitly name _foo as Something.Singleton.foo in the doc comment, marking it as a public function (you could dispense with @public if you didn’t name your inner function with an underscore, but this tells jsdoc-toolkit to treat it as private unless told otherwise):

    /**
     * This is the singleton.
     *
     * @namespace Something.Singleton
     */
    Something.Singleton = (function() {
      /**
       * @name Something.Singleton#foo
       * @public
       * @function
       * Foo method.
       *
       * @return {String} this method always returns with <code>bar</code>
       */
      function _foo() { return "bar"; }
    
      return {
        foo: _foo
      };
    }());
    

    This will produce the code documentation you’re looking for, and puts the comment next to the actual code it relates to. It doesn’t fully satisfy one’s need to have the computer do all the work – you have to be very explicit in the comment – but I think it’s just as clear, if not more so, than what you had originally, and I don’t think it’s much more maintenance (even in your original example, you’d have to change all your doc comments if you renamed Something.Singleton).

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

Sidebar

Related Questions

I've got a JavaScript object, built this way: function foo() { this.length = 0;
I have javascript object defined like this: function SocialMiner() { var verbose=true; var profileArray=new
I have a JavaScript function, pop_item . I have to call this from PHP,
I have a Javascript object that (very simplified) looks like this if('undefined' !== typeof(listCtrls)){
I have a JavaScript method that I need to run on one of my
I have a javascript function that manipulates the DOM when it is called (adds
We have a JavaScript function named move which does just windows.location.href = any given
I have a javascript function (class) that takes a function reference as one paremter.
I have JavaScript function call to changeMapLocation function where in it I want to
I'm trying to have JavaScript call a function from my ActionScript. ActionScript: import flash.external.ExternalInterface;

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.