//////////
// 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...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.