Script Includes

SarthakK
Tera Contributor

How To Make Script Include Private and Public

4 REPLIES 4

GlideFather
Tera Patron

Hi @SarthakK,

 

script include doesn't do anything itself, to execute the code it must be called. And these calls can be allowed/restricted.

 

You can set the scope - all scopes or just the given (custom) scope and also client callable.

 

Is it what you asked? If not, could you possibly elaborate a bit more on what you want to achieve?

_____
100 % GlideFather experience and 0 % generative AI

yashkamde
Tera Guru

Hello  @SarthakK ,

 

In short simply use "_" To Make Script Include Private,

For ex :

myPublicFunction: function() {
        // This function is public and can be called externally.
        this._myPrivateFunction();
        gs.info("Public function");
    },

    _myPrivateFunction: function() {
        // This function is private and only accessible within this script include.
        gs.info("Private function");
    },

 

If my response helped mark as helpful and accept the solution.

Aditya_hublikar
Kilo Sage

Hello @SarthakK ,

 

By simply using  _  (underscore) before your script include function it will  make script include function as private and without underscore script include function  remains public .

 

Private function script include which can be accessed/called from same script include or child script include, which means it cannot be called in background script or Fix script directly.

 

example : Private function in script include 

_getData:function()

{

//your code
}

 

example : public function in script include 

getData:function()

{

//code

}

 

If this helps you then mark it as helpful and accept as solution.

Regards,

Aditya,

Technical Consultant

GlideFather
Tera Patron

@Aditya_hublikar and @yashkamde 

Are you sure that adding "_" in the function name makes it automatically private?

I just tested in a background script calling a scoped script include from global and it worked. While marking the script include callable from the scope only it was restricted...

 

The same functions

var sandstormUtil = Class.create();
sandstormUtil.prototype = {

    initialize: function() {},

    myPublicFunction: function() {
        return this._myPrivateFunction();
    },

    _myPrivateFunction: function() {
        return "Private function";
    },

    type: 'sandstormUtil'
};

 

When having a script include callable from all scopes, then calling from global returns:

GlideFather_0-1771347736063.png

 

When having a script include callable from the script include's scope only, then calling from global returns:

GlideFather_1-1771347763780.png

 

This is how I understood setting privacy for a script include and haven't found any documentation nor article about the "_" making it private. It seems to me that it is only a naming convention but not any functional property.

 

Could you please share something to show me how the "_" makes it private? I want to know what I am doing wrong and to learn your way.

 

Thank you in advance!

 

 

EDIT: I tried with the getData() versus _getData() with the same result:

GlideFather_2-1771348208709.png

What am I doing wrong?

_____
100 % GlideFather experience and 0 % generative AI