JSFiddle - React, Tailwind, and code Playground

jsdoc using @methodOf + # prototype construct.

by Laurens Maneschijn

JavaScript

//////////
// INTENDED use of @methodOf + #
//////////

/**
 * @typedef MyClassLikeThing
 */
function MyClassLikeThing() {
}
/**
 * @memberOf MyClassLikeThing#
 * @param {string} str
 * @return {string}
 */
MyClassLikeThing.prototype.hello = function(str){
  return 'hello ' + str;
}


var myclasslikething = new MyClassLikeThing();

// all ok, calling hello found in prototype of object:
myclasslikething.hello('me'); 

// this will get a warning, as it is not a string:
myclasslikething.hello(4);


//////////
// normal use of @methodOf :
//////////

/**
 * @typedef MyClassLikeThing2
 */

/**
 * @return {MyClassLikeThing2}
 */
function getMyClassLikeThing2(){
/**
 * @memberOf MyClassLikeThing2#
 * @param {string} str
 * @return {string}
 */
	function hello (str){
		return 'hello ' + str;
	}
	return {
		hello: hello,
	}
}

var myclasslikething2 = getMyClassLikeThing2();
// this works, as hello is indeed a function of the object:
myclasslikething2.hello('you');

// this will now produce a warning as PhpStorm knows getMyClassLikeThing2 returns a {getMyClassLikeThing2} which has a function hello.
myclasslikething2.hello(5);

//////////
// and here is what we use:
//////////

/**
 * @typedef MyClassLikeThing3
 */


define(
	// name of this thing:
	'myclasslikething3',
	// stuff we require from elsewhere:
	[
		"$",
		"helper/util",
	], 
	// which is then passed as arguments into this function;
	/**
	 * @param {jQuery}
	 * @param {someutil}
	 * @return {MyClassLikeThing3}
	 */
	function(
		$,
		util
	) {
		// This is where the magic happens, note the "#".
		// Without it PhpStorm doesn't know all 
		// {MyClassLikeThing3} have this hello function
		// but if we add the "#" it suddenly just works.
		/**
		 * @memberOf MyClassLikeThing3#
		 * @param {string} str
		 * @return {string}
		 */
		function hello (str){
			return 'hello ' + str;
		}
		return {
			hello: hello,
		}
	}
);

// so far so good, but now we have another module using...