0

This question is very similar to another one on this site, except that there is one more restriction: I cannot modify the function that creates new functions.

Let's say we have an object named someObject with a method called addMethod that can be used to create new methods for this object like this:

someObject.addMethod( "methodName", function () {
    // Do some stuff here
} );

I want to document someObject using jsDoc, but I am not allowed to modify it except through the use of its addMethod function. Is there a way to do this?

Jean-François Beauchamp
  • 5,027
  • 8
  • 37
  • 74

1 Answers1

0

In the end, the only way I found was not to use an anonymous function and to use the @memberof jsDoc tag like this:

someObject.addMethod("publicName", myPublicMethod);

/**
 * @function
 * @memberof SimpleObject#
 * @desc
 * The description of myPublicMethod.
 *
 * @returns true if  can capture the display.
 */
function myPublicMethod() {

};

I thought I would have to use @memberof! (the forced form of @memberof; notice the exclamation mark), but it was not necessary. It works even if the function is not defined inside the SomeObject class.

Jean-François Beauchamp
  • 5,027
  • 8
  • 37
  • 74