Use of this code (var c = this;) in widget controller

goru
Tera Contributor

In service portal widgets, i am seeing some widgets are using "var c = this;" and some widgets are not using in controller part of widget.Please let me know use of this code (var c = this;) particular.

2 REPLIES 2

Ragini Kukade
Kilo Guru

Hi goru,

var c=this;

That is used to bind client script and server script within a widget.

 

example:-

c.server.update - here controller is used to update the server script from client script.

mark it as correct/helpful if you find it helpful.

Regards,

Ragini 

Sai120
ServiceNow Employee
ServiceNow Employee

Hi Goru

 

There is a lot of significance for "this" keyword. It may vary depends on situation where it is used. It refers to the client script object.

you can assign "this" to any javascript variable.

Here is the link which might give you more info:  https://toddmotto.com/understanding-the-this-keyword-in-javascript/

Please Mark Helpful/Correct, if it is helpful to you.

 

Regards

Sai