what is the underscore for in this._gr?

Michael Murphy
Tera Expert

Hi everyone,

I am relatively inexperienced developer and was wondering if anyone can tell me the significance of the underscore after a this. statement.  for example I'm trying to work out how to get a Cancel Change UI Action to work on a change request that is at the Review stage.  This has lead me to the ChangeRequestStateHandler script include with is an extension of the ChangeRequestStateHandlerSNC script include (I understand that the SNC is protected by Servicenow) but in that I have come across this._ and google isn't coming up with the goods.

Example:

/**
* @param changeRequestGr - GlideRecord
*/
initialize: function(changeRequestGr) {
this._initPrivateCacheable(ChangeRequestStateHandlerSNC.CHG_TYPE_MODEL_CACHE);

this.log = new GSLog(ChangeRequestStateHandlerSNC.LOG_PROPERTY, this.type);
this.log.setLog4J();

this._changeUtils = new ChangeUtils();

if (!changeRequestGr)
return;

// If the we're enforcing data requirements, check approvals for change on canMove.
this._checkApproval = gs.getProperty(ChangeRequestSNC.ENFORCE_DATA_REQ_PROP) === "true" ? true : false;

this._gr = changeRequestGr;
this._resetModel();
},

 

so what is the difference between this.checkApproval and this._checkApproval ?

1 ACCEPTED SOLUTION

Michael Jones -
Giga Sage

An _ before a function indicates that the function is private to the object that contains it; generally speaking it means it should only be called by "this" internally, rather than being called as a method externally. 

This gives a good description: 

https://www.thoughtco.com/and-in-javascript-2037515

I hope this helps!

If this was helpful or correct, please be kind and remember to click appropriately!

Michael Jones - Proud member of the CloudPires team!

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

View solution in original post

1 REPLY 1

Michael Jones -
Giga Sage

An _ before a function indicates that the function is private to the object that contains it; generally speaking it means it should only be called by "this" internally, rather than being called as a method externally. 

This gives a good description: 

https://www.thoughtco.com/and-in-javascript-2037515

I hope this helps!

If this was helpful or correct, please be kind and remember to click appropriately!

Michael Jones - Proud member of the CloudPires team!

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!