I’m a total newbie at JSDoc - so sorry (in advance) for the “stupid” question… but… if you make your OWN object - how do you work the JSDoc stuff so it will recognize it - and not give you 1,000,000 error markers when you reference the properties?
For that particular object, this should handle it for you. This is the inline version, but you can use the same notation for method headers if you return custom objects.
James, James! Yes, this is exactly what I was looking for!
Also, when you have a function that builds your object - I set it to @constructor as well - is that correct?
The issue I’m having is that I create a bunch of complex objects - and most of the time the JSDoc will recognize the properties. However, I do “store” the object in a global media field - and that’s where JSDoc doesn’t like things.
I guess I need to make a local variable with the object ?? or ??
bobcusick1332964082:
Also, when you have a function that builds your object - I set it to @constructor as well - is that correct?
The issue I’m having is that I create a bunch of complex objects - and most of the time the JSDoc will recognize the properties. However, I do “store” the object in a global media field - and that’s where JSDoc doesn’t like things.
I guess I need to make a local variable with the object ?? or ??
Sorry for the newbie, stupid questions!
I’m sure someone much better than me might answer this, but if not, I think that when you create your global variable as a media field, you then add in the JSDoc comment block above it a
@type {myObj}
or something like that and it should help.
Another great point I learnt is that in the ‘Problems’ tab, click on the ‘triangle’ and change the setting to ‘Show’ ‘Errors/Warnings on Selection’ rather than the normal setting (you can also turn on ‘All Errors’) and then it only shows you the Warnings for what you have selected (e.g. the form that you are on or the script editor you are in etc.). It REALLY helps me as then I can address just the problems in what I am working with, rather than trying to cope with hundreds of warnings
As far as I know the @constructor tag only changes the function’s icon in Developer (someone correct me if I’m wrong).
Basically what your’e talking about is defining Types for your application. Assuming that you’re working with scopes this is an example of going about what your’e trying to accomplish (pretend this code lives in a scope called ‘DocTest’):
/**
* The Type we want to define. Basically only serves as a documentation reference point
* @type {{name:String, status:Number}}
* @properties={typeid:35,uuid:"6B0521E1-28E1-4A5C-949B-54B2F440EAC0",variableType:-4}
*/
var TypeAnnotation;
/**
* Your 'global' stored value. We can denote it's type here, so Servoy has more to work with than just plain 'media'
* @type {scopes.DocTest.TypeAnnotation}
*
* @properties={typeid:35,uuid:"699D34C9-BC88-44D7-9D8D-4312DFBC39CB",variableType:-4}
*/
var storedValue;
/**
* Simple 'constructor' for your type
* @return {scopes.DocTest.TypeAnnotation}
* @properties={typeid:24,uuid:"A5314E0E-D83C-4CA5-A389-F4F97B4C7A7D"}
*/
function makeTypeAnnotation(){
/** @type {scopes.DocTest.TypeAnnotation} */
var o = { name :"c", status:1}
return o
}
/**
* Function that takes your type as a parameter, and set's it to the 'global'
* @param {scopes.DocTest.TypeAnnotation} a
* @properties={typeid:24,uuid:"C743D8F3-29F1-478B-A2B0-1AA97D2EA1A6"}
*/
function example(a) {
var x = makeTypeAnnotation();
x.name = a.name;
x.status = a.status;
storedValue = x;
}
Johan recently corrected on a better way to accomplish this. It’s more in line with standard JavaScript and has better support within Servoy.
Assume the following code is in a scope called “typeScope”
/**
* @constructor
*
* @param name
* @param status
*
* @properties={typeid:24,uuid:"14FD6B01-4ED6-4F3B-8B58-2607B08ACD16"}
*/
function MyType(name, status) {
this.name = name;
this.status = status;
/**
* @return {String}
*/
this.toString = function () {
return this.name + "(" + this.status + ")";
}
/**
* @param {String} newName
*/
this.setName = function (newName) {
this.name = newName;
}
}
/**
*
* @param {MyType} t
*
* @properties={typeid:24,uuid:"8C6DDA9E-5A5B-474F-AAF2-7309828E4343"}
*/
function inLocalScope(t) {
application.output(t.name);
}
/**
* @return {MyType}
* @properties={typeid:24,uuid:"245532EE-A40B-4102-8371-E70D344891EB"}
*/
function creationExample() {
var x = new MyType("Bob", "Enlightened");
return x;
}
And this would be an example of how to use this type in a different scope
/**
*
* @param {scopes.typeScope.MyType} t
*
* @properties={typeid:24,uuid:"1D407932-C9DA-422D-92F5-989C8622605E"}
*/
function inADifferentScope(t) {
application.output(t.name);
}
As you can see, when you are working with the type n the scope it’s defined in, you can just reference it as “MyType”, and create it using standard JavaScript type creation methods. It’s only when the type is in a different scope that you need to refer to it with its fully qualified name (scopes.typeScope.MyType).