Server-side GlideRecord objects contain an element for each field in the table that the record is in. These elements are not primitive values (strings, numbers, booleans), but Objects. The type of object is GlideElement, and the GlideElement API is available. However, since JavaScript is a "loosely typed" language, you can reassign a variable of one data-type (such as an Object) to another type (such as a string) without any hassle. Thus, setting a GlideRecord (gr) element's value to a string will overwrite the reference to the GlideElement object itself. This bad-practice example would look like:
gr.short_description = 'New short desc.';
Primitive values are stored on the stack, and are accessed directly by variable name. You might say that they are "contained within" a variable. A reference value on the other hand, is merely a pointer (or, you might say, a reference!) to an object which is stored on the heap. The difference between the heap and stack isn't important here, but it is important is that they're different. An object variable in JavaScript does not technically contain an object, but rather it contains a reference to that object. Consider what might print out, if we run the following in a background script:
var parent = { prop1: 'val1' }; var child = parent; child.prop1 = 'new value'; gs.print(parent.prop1);
In the above example, we declare an object: parent...
Read more