JSDoc Object Functions

Questions, tips and tricks and techniques for scripting in Servoy

JSDoc Object Functions

Postby kwpsd » Sat Jan 17, 2015 11:50 pm

Servoy Version: 7.4.2 - build 2033

I created a JavaScript object that contains properties along with private and public methods. The public methods are of the form:

Code: Select all
    this.functionName = function( parameterName )
    {
        ...do some processing...

        return someValue
    }


The object methods work fine, but the JSDoc (or lack thereof) is generating a warning (100's in my case) every time the object's methods are used. The warning message is:

Call to something which is not known to be a function


In Developer, when I reference the object, IntelliSense/Autocomplete shows the function as a property, not a function.

What is the best way to JSDoc annotate object functions in order to eliminate the warnings?

Thanks!
Kim W. Premuda
San Diego, CA USA
User avatar
kwpsd
 
Posts: 687
Joined: Sat Jul 28, 2007 6:59 pm
Location: San Diego, CA USA

Re: JSDoc Object Functions

Postby jgarfield » Sun Jan 18, 2015 5:54 pm

This should do the trick

Code: Select all
/**
* Doc String
* @param {String} parameterName
* @return {Number}
*/
this.functionName = function( parameterName )
{
    ...do some processing...

    return someValue
}
Programmer.
adBlocks
http://www.adblocks.com
jgarfield
 
Posts: 223
Joined: Wed Sep 28, 2005 9:02 pm
Location: Boston, US

Re: JSDoc Object Functions

Postby kwpsd » Mon Jan 19, 2015 9:12 am

Thank you for responding.

Adding the JSDoc annotation to the object's methods does not get rid of the warnings (I tried with and without the annotation). When adding the annotation, I used the ALT-SHIFT-J method just to make certain it was being added correctly. The warnings are at the instance of the object's usage, not in the object itself. For example,

var x = scopes.globals.objectName.functionName()

emits the warning (even though the function works).
Kim W. Premuda
San Diego, CA USA
User avatar
kwpsd
 
Posts: 687
Joined: Sat Jul 28, 2007 6:59 pm
Location: San Diego, CA USA

Re: JSDoc Object Functions

Postby jcompagner » Mon Jan 19, 2015 11:10 am

what is exactly the code that you have that creates that object?
And where do you exactly use it?
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8829
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: JSDoc Object Functions

Postby kwpsd » Mon Jan 19, 2015 11:58 pm

Our solution has many modules of which one is a 'core' module. The declaration of the _oSystem object as well as the class definiton of the object are in the 'core' module.

Code: Select all
/**
* @properties={typeid:35,uuid:"85A98ABB-29CD-4E16-BAC3-6E94EB301B79",variableType:-4}
*/
var _oSystem = {};


Code: Select all
/**
* @properties={typeid:24,uuid:"915ABC14-6C82-4955-AB08-B498609FA02D"}
*
*/
function classARMSystem()
{
    // DEFAULT PROPERTIES
   
    this.FacilityID = 'ARMSD';
    this.FacilityName = 'Animal Resource Management';
    this.Country = 'USA';
    this.ReportHeading = '';
    this.PainLevel1 = 'A';
    this.PainLevel2 = 'B';
    this.PainLevel3 = 'C';
    this.PainLevel4 = 'D';
    this.PainLevel5 = 'E';
    this.OrderFundRequired = 'Yes';
    this.OrderOveragePerCent = 0;
    this.confirmRecordChanges = false;
   
    // INTERNAL METHODS:
   
    /**
     * @param {String} pKey
     *
     * @return {String}
     */
    function getConfigurationItem( pKey )
    {
        var sql = 'SELECT arm_configuration_value FROM arm_configuration WHERE arm_configuration_key = ?';
           
        var ds = databaseManager.getDataSetByQuery( 'arm_data', sql, [ pKey ], -1 );
       
        if ( ds.getMaxRowIndex() > 0 ) return ds.getValue( 1, 1 );
       
        return null;
    }
   
   
    // EXTERNAL METHODS
   
   
    /**
     * @param {String} pItemName
     *
     * @return {String}
     */
    this.getItem = function( pItemName )
    {
        return getConfigurationItem( pItemName );
    }
   
   
   
    /**
     * @return
     */
    this.load = function ()
    {
        this.FacilityID = getConfigurationItem( 'Facility ID' );
        this.FacilityName = getConfigurationItem( 'Facility Name' );
        this.Country = getConfigurationItem( 'Country' );
        this.ReportHeading = getConfigurationItem( 'Report: Company Heading' );
        this.PainLevel1 = getConfigurationItem( 'Protocol: Pain Level 1' );
        this.PainLevel2 = getConfigurationItem( 'Protocol: Pain Level 2' );
        this.PainLevel3 = getConfigurationItem( 'Protocol: Pain Level 3' );
        this.PainLevel4 = getConfigurationItem( 'Protocol: Pain Level 4' );
        this.PainLevel5 = getConfigurationItem( 'Protocol: Pain Level 5' );
        this.OrderFundRequired = getConfigurationItem( 'Order: Fund Required?' );
        this.OrderOveragePerCent = parseFloat( getConfigurationItem( 'Order: Per Cent Overage' ) );

        var x = getConfigurationItem( 'System: Confirm Record Changes' );
       
        this.confirmRecordChanges = ( x == 'Yes' ) ? true : false;
    }

    /**
     * @return
     */
    this.display = function()
    {
        var message = 'oSystem Contents:\n' +
                      '    ' + this.FacilityID + '\n' +
                      '    ' + this.FacilityName + '\n' +
                      '    ' + this.Country + '\n' +
                      '    ' + this.ReportHeading + '\n' +
                      '    ' + this.PainLevel1 + '\n' +
                      '    ' + this.PainLevel2 + '\n' +
                      '    ' + this.PainLevel3 + '\n' +
                      '    ' + this.PainLevel4 + '\n' +
                      '    ' + this.PainLevel5 + '\n' +
                      '    ' + this.OrderFundRequired + '\n' +
                      '    ' + this.OrderOveragePerCent + '\n'
                      '    ' + this.confirmRecordChanges + '\n';
                     
        plugins.dialogs.showInfoDialog( 'DEBUG: oSystem Object', message, 'OK' );
    }

   
    /**
     * @return {String[]}
     */
    this.getPainLevelNames = function ()
    {
        return [ this.PainLevel1, this.PainLevel2, this.PainLevel3, this.PainLevel4, this.PainLevel5 ];
    }
}


Below is typical code usage:

Code: Select all
    var InOut = globals._oSystem.getItem( 'Billing: Care Day Count Method (In/Out or Total)' )
Kim W. Premuda
San Diego, CA USA
User avatar
kwpsd
 
Posts: 687
Joined: Sat Jul 28, 2007 6:59 pm
Location: San Diego, CA USA

Re: JSDoc Object Functions

Postby jcompagner » Thu Jan 22, 2015 11:09 am

but _oSystem is not typed at all
I guess you just assign it somewhere to an instance of that classARMSystem ?

but if you do this:

globals._oSystem.

then _oSystem is just an object because thats how you init it and it is not really typed
i would expect at least something like:

Code: Select all
/**
* @type {classARMSystem}
* @properties={typeid:35,uuid:"85A98ABB-29CD-4E16-BAC3-6E94EB301B79",variableType:-4}
*/
var _oSystem = {};
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8829
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: JSDoc Object Functions

Postby kwpsd » Fri Jan 23, 2015 2:00 am

This object design was designed/created in early 2010 with a much earlier version of Servoy. Originally, the object was typed as follows:

Code: Select all
// * @type {{FacilityID:String, FacilityName:String, Country:String, ReportHeading:String, PainLevel1:String, PainLevel2:String, PainLevel3:String, PainLevel4:String, PainLevel5:String, OrderFundRequired:String, OrderOveragePerCent:Number, confirmRecordChanges:Boolean, load:null, getItem:String }}


Thinking that this could be the cause of the warnings, the object 'type' was removed altogether, but it did not make a difference. I tried your 'type' suggestion as well (copied it verbatim), but, it too, did not make any difference.

The global object is declared in the core module using the 'add variable' method for that module and selecting 'media' type (just as you show it). The object class is in the same core module.

I vaguely recall seeing something in the referenced JSDoc links in the Servoy wiki about a '@method' type, but I do not believe Servoy supports this. Do you have any other suggestions...perhaps, a way to turn off this warning?
Kim W. Premuda
San Diego, CA USA
User avatar
kwpsd
 
Posts: 687
Joined: Sat Jul 28, 2007 6:59 pm
Location: San Diego, CA USA

Re: JSDoc Object Functions

Postby kwpsd » Fri Jan 23, 2015 2:47 am

I spoke too soon...I just restarted Servoy Developer and the warnings went away using your 'type':

Code: Select all
   /**
    * @type {classARMSystem}
    * @properties={typeid:35,uuid:"85A98ABB-29CD-4E16-BAC3-6E94EB301B79",variableType:-4}
    */
    var _oSystem = {};


Thanks so much, Johan! This is a huge relief for me.
Kim W. Premuda
San Diego, CA USA
User avatar
kwpsd
 
Posts: 687
Joined: Sat Jul 28, 2007 6:59 pm
Location: San Diego, CA USA


Return to Methods

Who is online

Users browsing this forum: No registered users and 11 guests